require "isodoc" require "twitter_cldr" module IsoDoc module Mpfd class Metadata < IsoDoc::Metadata def initialize(lang, script, labels) super set(:status, "XXX") end def title(isoxml, _out) main = isoxml&.at(ns("//title[@language='en']"))&.text set(:doctitle, main) end def subtitle(_isoxml, _out) nil end def author(isoxml, _out) tc = isoxml.at(ns("//editorialgroup/committee")) set(:tc, tc.text) if tc end def docid(isoxml, _out) docnumber = isoxml.at(ns("//bibdata/docidentifier")) docstatus = isoxml.at(ns("//bibdata/status")) dn = docnumber&.text if docstatus set(:status, status_print(docstatus.text)) abbr = status_abbr(docstatus.text) dn = "#{dn}(#{abbr})" unless abbr.empty? end set(:docnumber, dn) end def doctype(isoxml, _out) b = isoxml.at(ns("//bibdata")) || return return unless b["type"] t = b["type"].split(/[- ]/). map{ |w| w.capitalize unless w == "MPF" }.join(" ") set(:doctype, t) end def status_print(status) status.split(/-/).map{ |w| w.capitalize }.join(" ") end def status_abbr(status) case status when "working-draft" then "wd" when "committee-draft" then "cd" when "draft-standard" then "d" else "" end end def version(isoxml, _out) super revdate = get[:revdate] set(:revdate_monthyear, monthyr(revdate)) edition = isoxml.at(ns("//version/edition")) and set(:edition, edition.text.to_i.localize. to_rbnf_s("SpelloutRules", "spellout-ordinal"). split(/(\W)/).map(&:capitalize).join) end MONTHS = { "01": "January", "02": "February", "03": "March", "04": "April", "05": "May", "06": "June", "07": "July", "08": "August", "09": "September", "10": "October", "11": "November", "12": "December", }.freeze def monthyr(isodate) m = /(?\d\d\d\d)-(?\d\d)/.match isodate return isodate unless m && m[:yr] && m[:mo] return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}" end def security(isoxml, _out) security = isoxml.at(ns("//bibdata/security")) || return set(:security, security.text) end end end end