require "isodoc" require "twitter_cldr" require "iso-639" module IsoDoc module Unece class Metadata < IsoDoc::Metadata def initialize(lang, script, labels) super end def title(isoxml, _out) main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='main']"))&.text set(:doctitle, main) end def subtitle(isoxml, _out) main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='subtitle']"))&.text set(:docsubtitle, main) end def extract_languages(nodeset) lgs = [] nodeset.each do |l| l && ISO_639&.find(l.text)&.english_name && lgs << ISO_639.find(l.text).english_name end lgs.map { |l| l == "Spanish; Castilian" ? "Spanish" : l } end def author(isoxml, _out) tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee")) set(:tc, tc.text) if tc set(:distribution, isoxml&.at(ns("//bibdata/ext/distribution"))&.text) lgs = extract_languages(isoxml.xpath(ns("//bibdata/language"))) lgs = [] if lgs.sort == %w(English French Arabic Chinese German Spanish).sort slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/submissionlanguage"))) lgs = [] if slgs.size == 1 set(:language, lgs) unless lgs.empty? set(:submissionlanguage, slgs) unless slgs.empty? session(isoxml, _out) end def multival(isoxml, xpath) items = [] isoxml.xpath(ns(xpath)).each { |i| items << i.text } items end def session(isoxml, _out) set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.text&.to_i&. localize&.to_rbnf_s("SpelloutRules", "spellout-ordinal")&.capitalize) set(:session_date, isoxml&.at(ns("//bibdata/ext/session/date"))&.text) set(:session_collaborator, isoxml&.at(ns("//bibdata/ext/session/collaborator"))&.text) set(:session_id, isoxml&.at(ns("//bibdata/ext/session/id"))&.text) set(:item_footnote, isoxml&.at(ns("//bibdata/ext/session/item-footnote"))&.text) set(:session_itemnumber, multival(isoxml, "//bibdata/ext/session/item-number")) set(:session_itemname, multival(isoxml, "//bibdata/ext/session/item-name")) set(:session_subitemname, multival(isoxml, "//bibdata/ext/session/subitem-name")) end def docid(isoxml, _out) dn = isoxml.at(ns("//bibdata/docidentifier"))&.text set(:docnumber, dn) type = isoxml&.at(ns("//bibdata/ext/doctype"))&.text set(:formatted_docnumber, type == "recommendation" ? "UN/CEFACT Recommendation #{dn}" : dn) 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 unpublished(status) !%w(published withdrawn).include? status.downcase end def version(isoxml, _out) super revdate = get[:revdate] set(:revdate_monthyear, monthyr(revdate)) 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 end end end