コンテンツにスキップ

モジュール:Kindle版

モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

{{Kindle版}}の内部モジュール。

使用法[編集]

{{#invoke:Kindle版|main}}

local p = {}

local WRAPPER = 'Template:Kindle版'

function p.error ( message )
	return '<strong class="error">エラー:' ..message ..'</strong><br />'
end

function p.main( frame )
	local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = WRAPPER, removeBlanks = false })
	if args[1] == nil or args[2] == nil then
		return p.error('入力省略は出来ません。')
	end

	local line_all = args[1] or '' -- 全行数
	local line = args[2] or '' -- 行位置 (type1: nnnn / type2: nnnn1-nnnn2)
	if line_all == '' or line == '' then
		return p.error('数値を入力して下さい。')
	end


	local line1 = ''
	local line2 = ''

	if not string.match(line, '-') then
		line1 = frame:preprocess('{{ {{{|safesubst:}}}#expr:(' ..line ..'/' ..line_all ..' round 2) * 100}}')
		line2 = ''
	else
		local split = mw.text.split( line, '-' )
		line1 = frame:preprocess('{{ {{{|safesubst:}}}#expr:(' ..split[1] ..'/' ..line_all ..' round 2) * 100}}')
		line2 = frame:preprocess('{{ {{{|safesubst:}}}#expr:(' ..split[2] ..'/' ..line_all ..' round 2) * 100}}')
		-- 近似値判定
		if line1 == line2 then
			line2 = ''
		else
			line2 = '-' ..line2
		end
	end

	return 'Kindle版、位置No.全' ..line_all ..'中 ' ..line ..' / ' ..line1 ..line2 ..'%'
end

return p