Módulo:Número de estrelas

Origem: Wikipédia, a enciclopédia livre.
local p = {}

function p._starnumber(num, maxnum) -- num of stats / maximal number of stars possible (shows grey stars for the difference)
    if not num then
        return nil
    end
    if not tonumber(num) then
        return num .. '(?)' -- error handling ?
    end
    num = tonumber(num)
    local maxnum = tonumber(maxnum) or num
    local starsize = '11px'
    if maxnum > 6 then
        starsize = '7px'
    end
    
    local str = ''
    local images = {
        full = 'Star full.svg',
        half = 'Star half.svg',
        empty = 'Star empty.svg'
    }
    local function addstar(startype)
        str = str .. '[[File:' .. images[startype] .. '|' .. starsize .. ']]'
    end

    for i = 1, math.floor(num) do
        addstar('full')
    end
    
    if num > math.floor(num) then -- meia estrela
        addstar('half')
    end
    
    for i = 1, (maxnum - math.ceil(num)) do
        addstar('empty')
    end
    
    return  '<span style="white-space:nowrap">' .. str  .. '</span>'
end

function p.starnumber(frame)
    return p._starnumber(frame.args[1], frame.args[2])
end

return p