Class: IsoDoc::Iso::Metadata

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

Constant Summary collapse

STAGE_ABBRS =
{
  "00": "PWI",
  "10": "NWIP",
  "20": "WD",
  "30": "CD",
  "40": "DIS",
  "50": "FDIS",
  "60": "IS",
  "90": "(Review)",
  "95": "(Withdrawal)",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, labels) ⇒ Metadata

Returns a new instance of Metadata.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/isodoc/iso/metadata.rb', line 6

def initialize(lang, script, labels)
  super
  @metadata = {
  tc: "XXXX",
  sc: "XXXX",
  wg: "XXXX",
  editorialgroup: [],
  secretariat: "XXXX",
  obsoletes: nil,
  obsoletes_part: nil
}
end

Instance Method Details

#author(xml, _out) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/isodoc/iso/metadata.rb', line 135

def author(xml, _out)
  super
  tc(xml)
  sc(xml)
  wg(xml)
  secretariat(xml)
end

#compose_title(main, intro, part, partnum, subpartnum, lang) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/isodoc/iso/metadata.rb', line 95

def compose_title(main, intro, part, partnum, subpartnum, lang)
  main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
  intro &&
    main = "#{@c.encode(intro.text, :hexadecimal)} — #{main}"
  if part
    suffix = part_title(part, partnum, subpartnum, lang)
    main = "#{main} — #{suffix}"
  end
  main
end

#docid(isoxml, _out) ⇒ Object



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

def docid(isoxml, _out)
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'iso']"))
  set(:docnumber, dn&.text)
  tcdn = isoxml.xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']"))
  set(:tc_docnumber, tcdn.map { |n| n.text })
end

#docstatus(isoxml, _out) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/iso/metadata.rb', line 44

def docstatus(isoxml, _out)
  docstatus = isoxml.at(ns("//bibdata/status/stage"))
  set(:unpublished, false)
  if docstatus
    set(:stage, docstatus.text)
    set(:stage_int, docstatus.text.to_i)
    set(:unpublished, unpublished(docstatus.text))
    set(:statusabbr, status_abbrev(docstatus.text,
                                   isoxml&.at(ns("//bibdata/status/substage"))&.text,
                                   isoxml&.at(ns("//bibdata/status/iteration"))&.text,
                                   isoxml&.at(ns("//version/draft"))&.text))
    unpublished(docstatus.text) and
      set(:stageabbr, stage_abbr(docstatus.text))
  end
  revdate = isoxml.at(ns("//version/revision-date"))
  set(:revdate, revdate&.text)
end

#doctype(isoxml, _out) ⇒ Object



179
180
181
182
183
184
# File 'lib/isodoc/iso/metadata.rb', line 179

def doctype(isoxml, _out)
  super
  ics = []
  isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
  set(:ics, ics.empty? ? "XXX" : ics.join(", "))
end

#part_label(lang) ⇒ Object

we don’t leave this to i18n.rb, because we have both English and French titles in the same document



75
76
77
78
79
80
# File 'lib/isodoc/iso/metadata.rb', line 75

def part_label(lang)
  case lang
  when "en" then "Part"
  when "fr" then "Partie"
  end
end

#part_prefix(partnum, subpartnum, lang) ⇒ Object



90
91
92
93
# File 'lib/isodoc/iso/metadata.rb', line 90

def part_prefix(partnum, subpartnum, lang)
  partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
  "#{part_label(lang)}&nbsp;#{partnum}"
end

#part_title(part, partnum, subpartnum, lang) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/isodoc/iso/metadata.rb', line 82

def part_title(part, partnum, subpartnum, lang)
  return "" unless part
  suffix = @c.encode(part.text, :hexadecimal)
  partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
  suffix = "#{part_label(lang)}&nbsp;#{partnum}: " + suffix if partnum
  suffix
end

#sc(xml) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/isodoc/iso/metadata.rb', line 154

def sc(xml)
  sc_num = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@number"))
  sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@type"))&.text || "SC"
  if sc_num
    scid = "#{sc_type} #{sc_num.text}"
    set(:sc, scid)
    set(:editorialgroup, get[:editorialgroup] << scid)
  end
end

#secretariat(xml) ⇒ Object



174
175
176
177
# File 'lib/isodoc/iso/metadata.rb', line 174

def secretariat(xml)
  sec = xml.at(ns("//bibdata/ext/editorialgroup/secretariat"))
  set(:secretariat, sec.text) if sec
end

#stage_abbr(stage) ⇒ Object



31
32
33
# File 'lib/isodoc/iso/metadata.rb', line 31

def stage_abbr(stage)
  self.class::STAGE_ABBRS[stage.to_sym] || "??"
end

#status_abbrev(stage, substage, iter, draft) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/isodoc/iso/metadata.rb', line 35

def status_abbrev(stage, substage, iter, draft)
  return "" unless stage
  stage = self.class::STAGE_ABBRS[stage.to_sym] || "??"
  stage = "PRF" if stage == "IS" && substage == "00"
  stage += iter if iter
  stage = "Pre" + stage if draft =~ /^0\./
  stage
end

#subtitle(isoxml, _out) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/isodoc/iso/metadata.rb', line 121

def subtitle(isoxml, _out)
  intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='fr']"))
  main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='fr']"))
  part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='fr']"))
  partnumber = isoxml.at(ns("//bibdata//project-number/@part"))
  subpartnumber = isoxml.at(ns("//bibdata//project-number/@subpart"))
  set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
  main = compose_title(main, intro, part, partnumber, subpartnumber, "fr")
  set(:docsubtitle, main)
  set(:docsubtitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
  set(:docsubtitlepartlabel, part_prefix(partnumber, subpartnumber, "fr"))
  set(:docsubtitlepart, @c.encode(part.text, :hexadecimal)) if part
end

#tc(xml) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/isodoc/iso/metadata.rb', line 143

def tc(xml)
  tc_num = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@number"))
  tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))&.
    text || "TC"
  if tc_num
    tcid = "#{tc_type} #{tc_num.text}"
    set(:tc,  tcid)
    set(:editorialgroup, get[:editorialgroup] << tcid)
  end
end

#title(isoxml, _out) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/isodoc/iso/metadata.rb', line 106

def title(isoxml, _out)
  intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='en']"))
  main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='en']"))
  part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='en']"))
  partnumber = isoxml.at(ns("//bibdata//project-number/@part"))
  subpartnumber = isoxml.at(ns("//bibdata//project-number/@subpart"))

  set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
  main = compose_title(main, intro, part, partnumber, subpartnumber, "en")
  set(:doctitle, main)
  set(:doctitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
  set(:doctitlepartlabel, part_prefix(partnumber, subpartnumber, "en"))
  set(:doctitlepart, @c.encode(part.text, :hexadecimal)) if part
end

#unpublished(status) ⇒ Object



62
63
64
# File 'lib/isodoc/iso/metadata.rb', line 62

def unpublished(status)
  status.to_i > 0 && status.to_i < 60
end

#wg(xml) ⇒ Object



164
165
166
167
168
169
170
171
172
# File 'lib/isodoc/iso/metadata.rb', line 164

def wg(xml)
  wg_num = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@number"))
  wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@type"))&.text || "WG"
  if wg_num
    wgid = "#{wg_type} #{wg_num.text}"
    set(:wg, wgid)
    set(:editorialgroup, get[:editorialgroup] << wgid)
  end
end