Module:reference information

Hello, you have come here looking for the meaning of the word Module:reference information. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:reference information, but we will also tell you about its etymology, its characteristics and you will know how to say Module:reference information in singular and plural. Everything you need to know about the word Module:reference information you have here. The definition of the word Module:reference information will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:reference information, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Retrieves information associated with ranges of pages (author name, title) for the reference and quotation templates {{R:sem-pro:FS Militarev}}, {{RQ:Hakluyt Principall Navigations}}, {{R:Textile Terminologies}}, {{R:sem-pro:Weninger-Handbook}}. Data found in Module:reference information/data, functions for individual templates in Module:reference information/functions.


local export = {}

local works = mw.loadData "Module:reference information/data"

local function retrieve_from_ranges(ranges, number)
	for _, range in ipairs(ranges) do
		if number < range then
			return nil
		elseif number <= range then
			return range
		end
	end
end

function export.retrieve_info(work, page, information)
	local data = works
	if not data then
		error("The work " .. work .. " is not found in ].")
	end
	
	local index = data.indices or error("The type of information " .. information .. " is not recognized.")
	
	local result = retrieve_from_ranges(data, page)
	-- If a function is listed in field "func" of data table, look up that
	-- function in ] and use it to generate
	-- the output.
	if data.func then
		local func = require("Module:reference information/functions")
			or error("There's no function by the name " .. data.func
				.. " in ].")
		return result and result
			and func(result, page)
	else
		return result and result
	end
end

local function process(param)
	if param == "" then
		return nil
	else
		return param
	end
end

-- The first parameter in the module invocation is the work, the second is which
-- info to return, and the page or pages parameter from the template instance
-- determines the number to search for in the ranges in ].
-- {{#invoke:reference information|retrieve|FS_Militaev|first}}
-- {{#invoke:reference information|retrieve|FS_Militaev|last}}
-- Any numbered parameters beginning with the third (optional) specify the
-- parameter or parameters in which the page number is to be found.
function export.retrieve(frame)
	local work = frame.args
	
	if not works then
		error("No data for " .. work .. " in ].")
	end
	
	local info = process(frame.args)
	
	local pargs = frame:getParent().args
	local page
	
	if frame.args then
		-- Parameter names have been supplied in parameters 3 and up of the
		-- module invocation.
		-- Check each in turn until we find one that has a value in the current
		-- template instance.
		local i = 3
		while not page and frame.args do
			local param = process(frame.args)
			param = tonumber(param) or param -- "2" -> 2
			page = process(pargs)
			i = i + 1
		end
	else
		page = process(pargs.page) or process(pargs.pages)
	end
	
	-- Get first sequence of digits in parameter: a lone number, or the first
	-- number of a range ("110–111" -> 110).
	if page then
		page = tonumber(page:match("%d+"))
	end
	
	if not page then
		return nil
	end
	
	-- Use first number in "page" parameter.
	return export.retrieve_info(work, page, info)
end

return export