Class: IsoDoc::Unece::Metadata

Inherits:
Metadata
  • Object
show all
Defined in:
lib/isodoc/unece/metadata.rb

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, labels) ⇒ Metadata

Returns a new instance of Metadata.



9
10
11
12
13
# File 'lib/isodoc/unece/metadata.rb', line 9

def initialize(lang, script, labels)
  super
          here = File.dirname(__FILE__)
set(:logo, File.expand_path(File.join(here, "html", "logo.jpg")))
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/isodoc/unece/metadata.rb', line 34

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 Russian Spanish).sort
  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)
end

#docid(isoxml, _out) ⇒ Object



65
66
67
68
69
70
# File 'lib/isodoc/unece/metadata.rb', line 65

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



25
26
27
28
29
30
31
32
# File 'lib/isodoc/unece/metadata.rb', line 25

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

#monthyr(isodate) ⇒ Object



107
108
109
110
111
# File 'lib/isodoc/unece/metadata.rb', line 107

def monthyr(isodate)
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
  return isodate unless m && m[:yr] && m[:mo]
  return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}"
end

#multival(isoxml, xpath) ⇒ Object



47
48
49
50
51
# File 'lib/isodoc/unece/metadata.rb', line 47

def multival(isoxml, xpath)
  items = []
  isoxml.xpath(ns(xpath)).each { |i| items << i.text }
  items
end

#session(isoxml, _out) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/isodoc/unece/metadata.rb', line 53

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

#status_abbr(status) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/isodoc/unece/metadata.rb', line 72

def status_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
# File 'lib/isodoc/unece/metadata.rb', line 20

def subtitle(isoxml, _out)
  main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='subtitle']"))&.text
  set(:docsubtitle, main)
end

#title(isoxml, _out) ⇒ Object



15
16
17
18
# File 'lib/isodoc/unece/metadata.rb', line 15

def title(isoxml, _out)
  main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='main']"))&.text
  set(:doctitle, main)
end

#unpublished(status) ⇒ Object



82
83
84
# File 'lib/isodoc/unece/metadata.rb', line 82

def unpublished(status)
  !%w(published withdrawn).include? status.downcase
end

#version(isoxml, _out) ⇒ Object



86
87
88
89
90
# File 'lib/isodoc/unece/metadata.rb', line 86

def version(isoxml, _out)
  super
  revdate = get[:revdate]
  set(:revdate_monthyear, monthyr(revdate))
end