Class: IsoDoc::UN::Metadata
- Inherits:
-
Metadata
- Object
- Metadata
- IsoDoc::UN::Metadata
- Defined in:
- lib/isodoc/un/metadata.rb
Instance Method Summary collapse
- #author(isoxml, _out) ⇒ Object
- #docid(isoxml, _out) ⇒ Object
- #extract_languages(nodeset) ⇒ Object
-
#initialize(lang, script, locale, labels) ⇒ Metadata
constructor
A new instance of Metadata.
- #multival(isoxml, xpath) ⇒ Object
- #session(isoxml, _out) ⇒ Object
- #session_id(isoxml) ⇒ Object
- #stage_abbr(status) ⇒ Object
- #subtitle(isoxml, _out) ⇒ Object
- #title(isoxml, _out) ⇒ Object
- #unpublished(status) ⇒ Object
Constructor Details
#initialize(lang, script, locale, labels) ⇒ Metadata
Returns a new instance of Metadata.
8 9 10 11 12 |
# File 'lib/isodoc/un/metadata.rb', line 8 def initialize(lang, script, locale, labels) super here = File.dirname(__FILE__) set(:logo, File.(File.join(here, "html", "logo.jpg"))) end |
Instance Method Details
#author(isoxml, _out) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/isodoc/un/metadata.rb', line 33 def (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.sort == %w(English French Arabic Chinese Russian Spanish).sort and lgs = [] slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/"\ "submissionlanguage"))) lgs = [] if slgs.size == 1 set(:doclanguage, lgs) unless lgs.empty? set(:submissionlanguage, slgs) unless slgs.empty? session(isoxml, _out) super end |
#docid(isoxml, _out) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/isodoc/un/metadata.rb', line 80 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 |
#extract_languages(nodeset) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/isodoc/un/metadata.rb', line 26 def extract_languages(nodeset) lgs = nodeset.each_with_object([]) do |l, m| l and lg = ISO_639.find(l.text) and m << lg.english_name end lgs.compact.map { |l| l == "Spanish; Castilian" ? "Spanish" : l } end |
#multival(isoxml, xpath) ⇒ Object
49 50 51 52 53 |
# File 'lib/isodoc/un/metadata.rb', line 49 def multival(isoxml, xpath) items = [] isoxml.xpath(ns(xpath)).each { |i| items << i.text } items end |
#session(isoxml, _out) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/isodoc/un/metadata.rb', line 55 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) session_id(isoxml) 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 |
#session_id(isoxml) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/isodoc/un/metadata.rb', line 73 def session_id(isoxml) sid = isoxml.at(ns("//bibdata/ext/session/id"))&.text set(:session_id, sid) set(:session_id_head, sid&.sub(%r{/.*$}, "")) set(:session_id_tail, sid&.sub(%r{^[^/]+}, "")) end |
#stage_abbr(status) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/un/metadata.rb', line 88 def stage_abbr(status) case status when "working-draft" then "wd" when "committee-draft" then "cd" when "draft-standard" then "d" else "" end end |
#subtitle(isoxml, _out) ⇒ Object
20 21 22 23 24 |
# File 'lib/isodoc/un/metadata.rb', line 20 def subtitle(isoxml, _out) main = isoxml.at(ns("//bibdata/title[@language='en' and @type='subtitle']")) &.children&.to_xml set(:docsubtitle, main) end |
#title(isoxml, _out) ⇒ Object
14 15 16 17 18 |
# File 'lib/isodoc/un/metadata.rb', line 14 def title(isoxml, _out) main = isoxml.at(ns("//bibdata/title[@language='en' and @type='main']")) &.children&.to_xml set(:doctitle, main) end |
#unpublished(status) ⇒ Object
98 99 100 |
# File 'lib/isodoc/un/metadata.rb', line 98 def unpublished(status) !%w(published withdrawn).include? status.downcase end |