User:קיפודנחש/sandbox/Module:Ranges

-- --Range|inrange|12|1 2 3..7 = one, two, three to seven| 9..40 = between nine and fourty}} will return "between nine and fourty". numerical values only. ranges are mared with lower..higher. numbers can be positive or negative, fractions, and use the "e" notation: -10..-7 is fine, 1e2..1e7 is fine, 1.234e19 is fine. the first, unnamed parameter is the value

function ranges( args ) local value function match( s ) if type( s ) == 'number' then return false end local chunks = {} s:gsub("%S+", function( c ) table.insert(chunks, c) end) for i = 1, #chunks do			local a, b = chunks[i]:match( "([^.]+)%.%.([^.]+)" ) a = tonumber( a ) b = tonumber( b ) if a and b and a <= value and value <= b or tonumber( chunks[i] ) == value then return true end end return false end value = tonumber( args[1] ) if not value then return '' end for k, v in pairs( args ) do		if match( k ) then return v end end return args['default'] or '' end

return { inrange = function( frame ) return ranges( frame.args ) end, }