Module:Gear attribute

local utils = require('Module:Utils') local yesno = require('Dev:Yesno') local categorize = utils.categorize('Catalog') local p = {} local gear_attributes = {'Melee weapon', 'Ranged weapon', 'Explosive', 'Building tool', 'Power up', 'Navigation enhancer', 'Musical instrument', 'Social item', 'Personal transport'} function p._format_gear_attribute(args) if args.gear_attribute then local gear_attribute_string = args.gear_attribute:lower -- Use the lowercase string for comparisons. if gear_attribute_string == 'melee' then gear_attribute_string = 'melee weapon' elseif gear_attribute_string == 'ranged' then gear_attribute_string = 'ranged weapon' elseif gear_attribute_string == 'building' then gear_attribute_string = 'building tool' elseif gear_attribute_string == 'navigation' then gear_attribute_string = 'navigation enhancer' elseif gear_attribute_string == 'musical' then gear_attribute_string = 'musical instrument' elseif gear_attribute_string == 'social' then gear_attribute_string = 'social item' elseif gear_attribute_string == 'transport' then gear_attribute_string = 'personal transport' end for _, gear_attribute in next, gear_attributes do           if gear_attribute:lower == gear_attribute_string then local output = " " .. gear_attribute if yesno(args.categorize) then output = output .. categorize(gear_attribute .. "s") end return output end end -- If the function didn't return in the loop, the gear_attribute string corresponded to none of the recognized gear attributes. return error("Invalid gear type") end end p.format_gear_attribute = utils.make_wrapper_function(p._format_gear_attribute) function p._enumerate_gear_attributes(args) if args.gear_attributes then local output = "" -- If there are multiple gear attributes, list them. -- Otherwise, we want to format the only gear attribute without putting it in a list. if args.gear_attributes:find('/') or args.gear_attributes:find(',') then for gear_attribute in args.gear_attributes:gmatch('%s*([^/,]+)') do               output = output .. "\n* " .. p._format_gear_attribute {gear_attribute = gear_attribute, categorize = args.categorize} end output = output:sub(2) -- Remove the initial newline. else output = p._format_gear_attribute {gear_attribute = args.gear_attributes, categorize = args.categorize} end return output end end p.enumerate_gear_attributes = utils.make_wrapper_function(p._enumerate_gear_attributes) return p