Module:Vanguard funds

-- Module to generate a Vanguard fund page URL from a fund id. -- Example usage: --  --   -- Console example: --  mw.log(p.lookup({fund="0585"})) --  mw.log(p.url({fund="0585"})) -- Notes: --  Input fund may be a fund symbol, an ETF ticker, or a fund number.

require('Module:No globals')

local p = {} local arguments = require('Module:Arguments')

local _lookup_table = mw.loadData('Module:Vanguard funds/data') local _search_url = "https://investor.vanguard.com/search"

function p._lookup(args) local fund = (args["fund"] or args[1] or ""):lower

local result = _lookup_table[fund] return result or "undefined" end

function p._url(args) local fund = (args["fund"] or args[1] or ""):lower

local lookup = _lookup_table[fund] if lookup == nil then local search = args["search_url"] or args[2] or _search_url

local title = mw.title.getCurrentTitle if title.namespace == 0 then return search .. ""		else return search .. ""		end end

local prefix = lookup:sub(1, 2) if prefix == "f:" then local stem = args["mutual_fund_stem"] or args[3] or _search_url .. "#q=" return stem .. lookup:sub(3)

elseif prefix == "e:" then local stem = args["etf_stem"] or args[4] or _search_url .. "#q=" return stem .. lookup:sub(3)

else assert(false, "Bad lookup table value: " .. lookup) end end

function p.lookup(frame) local args = arguments.getArgs(frame,		{trim = true, removeBlanks = true, frameOnly = true}) return p._lookup(args) end

function p.url(frame) local args = arguments.getArgs(frame,		{trim = true, removeBlanks = true, frameOnly = true}) return p._url(args) end

return p