Module:Roma
Appearance
Documentation for this module may be created at Module:Roma/doc
local Roma = {};
function _validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong )
local errors = {};
local struct = {
{ "latitude degrees", tonumber( lat_d ) or 0, -90, 90, 0 }, -- last 0 is for "strong" mode
{ "latitude minutes", tonumber( lat_m ) or 0, 0, 59 },
{ "latitude seconds", tonumber( lat_s ) or 0, 0, 59 },
{ "longitude degrees", tonumber( long_d ) or 0, -360, 360, 0 },
{ "longitude minutes", tonumber( long_m ) or 0, 0, 59 },
{ "longitude seconds", tonumber( long_s ) or 0, 0, 59 }
};
for _, item in ipairs(struct) do
if item[2] < item[3] then
table.insert(errors, {source, item[1] .. " < " .. item[3] });
end
if item[2] > item[4] then
table.insert(errors, {source, item[1] .. " > " .. item[4] });
end
if strong and item[5] and item[2] < item[5] then
table.insert(errors, {source, item[1] .. " < " .. item[5] .. " with hemisphere flag"});
end
end
return errors;
end
function Roma.validate(frame)
local args = frame.args;
if #args < 7 then
return '<span class="error">Incorrect input.</span>';
end
local errors = _validate( args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8] );
if errors[1] ~= nil then
return errors[1][2];
end
return 'All correct.';
end
-- an example to local interpreter
--local surok = _validate( -5, 33, 44, 55, 26, 27, 'Сурок', true );
--print(surok[1][2]);
--return 0;
return Roma;