Class: IsoDoc::Mpfd::Metadata

Inherits:
IsoDoc::Metadata
  • Object
show all
Defined in:
lib/isodoc/mpfd/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.



8
9
10
11
# File 'lib/isodoc/mpfd/metadata.rb', line 8

def initialize(lang, script, labels)
  super
  set(:status, "XXX")
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



22
23
24
25
# File 'lib/isodoc/mpfd/metadata.rb', line 22

def author(isoxml, _out)
  tc = isoxml.at(ns("//editorialgroup/committee"))
  set(:tc, tc.text) if tc
end

#docid(isoxml, _out) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/isodoc/mpfd/metadata.rb', line 27

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

#doctype(isoxml, _out) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/isodoc/mpfd/metadata.rb', line 39

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

#monthyr(isodate) ⇒ Object



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

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

#security(isoxml, _out) ⇒ Object



92
93
94
95
# File 'lib/isodoc/mpfd/metadata.rb', line 92

def security(isoxml, _out)
  security = isoxml.at(ns("//bibdata/security")) || return
  set(:security, security.text)
end

#status_abbr(status) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/mpfd/metadata.rb', line 51

def status_abbr(status)
  case status
  when "working-draft" then "wd"
  when "committee-draft" then "cd"
  when "draft-standard" then "d"
  else
    ""
  end
end

#status_print(status) ⇒ Object



47
48
49
# File 'lib/isodoc/mpfd/metadata.rb', line 47

def status_print(status)
  status.split(/-/).map{ |w| w.capitalize }.join(" ")
end

#subtitle(_isoxml, _out) ⇒ Object



18
19
20
# File 'lib/isodoc/mpfd/metadata.rb', line 18

def subtitle(_isoxml, _out)
  nil
end

#title(isoxml, _out) ⇒ Object



13
14
15
16
# File 'lib/isodoc/mpfd/metadata.rb', line 13

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

#version(isoxml, _out) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/mpfd/metadata.rb', line 61

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