Jump to content

Module:PickRow: Difference between revisions

From p1gwars
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
     end
     end


     for _, row in ipairs(tab.data) do
     for i, row in ipairs(tab.data) do
         if row[column] ~= "Tijgertje I" then
         if row[column] ~= args.filter then
             for c, _ in ipairs(row) do
             for c, _ in ipairs(row) do
                 if tab.schema.fields[c].type == "number" then
                 if tab.schema.fields[c].type == "number" then
                     row[c] = 1
                     row[c] = 0
                 end
                 end
             end
             end
Line 17: Line 17:
     end
     end
     return tab
     return tab
end
-- Put p.test() in the debug console while you're editing the code to test
-- with a specific sample data set / args
function p.test(column, filter, tabname)
    -- pass "_" for lang to get the raw multilingual source data
    local tab = mw.ext.data.get(tabname or "Test.tab", "_", "LocalData")
    local args = {
      ["column"] = column or 1,
      ["filter"] = filter or "Tijgertje I"
    }
    tab = p.pick_row(tab, args)
    return mw.dumpObject(tab)
end
end


return p
return p

Latest revision as of 20:58, 11 January 2026

Documentation for this module may be created at Module:PickRow/doc

local p = {}
local column = 0

function p.pick_row(tab, args)
    if tonumber(args.column) > 0 then
        column = tonumber(args.column)
    end

    for i, row in ipairs(tab.data) do
        if row[column] ~= args.filter then
            for c, _ in ipairs(row) do
                if tab.schema.fields[c].type == "number" then
                    row[c] = 0
                end
            end
         end
     end
     return tab
end

-- Put p.test() in the debug console while you're editing the code to test
-- with a specific sample data set / args
function p.test(column, filter, tabname)
    -- pass "_" for lang to get the raw multilingual source data
    local tab = mw.ext.data.get(tabname or "Test.tab", "_", "LocalData")
    local args = {
       ["column"] = column or 1,
       ["filter"] = filter or "Tijgertje I"
    }
    tab = p.pick_row(tab, args)
    return mw.dumpObject(tab)
end

return p