Jump to content

Module:Scientific American volume issues

From Wikisource

require('strict')

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs

local function pad_number(n, pad)
	n = tostring(n)
	return string.rep("0", pad - string.len(n)) .. n
end

function p.scientific_american_volume_issues(frame)
	local args = getArgs(frame)
	
	local volume = tonumber(args.volume) or 1
	local series = tonumber(args.series) or 1
	local issues = tonumber(args.issues) or 52
	
	local padded_volume = pad_number(volume, 3)
	local volume_list = {}
	for i = 1, issues do
		volume_list[i] = "* [[Index:Scientific American - Series " .. series .. " - Volume " .. padded_volume .. " - Issue " .. pad_number(i, 2) .. ".pdf|" .. i .. "]]"
	end
	
	return "'''Volume " .. volume .. " issues:''' " .. frame:expandTemplate {
		['title'] = 'flatlist',
		['args'] = {table.concat(volume_list, "\n")}
	}
end

return p