Class: IsoDoc::Iso::Metadata
- Inherits:
-
Metadata
- Object
- Metadata
- IsoDoc::Iso::Metadata
- Defined in:
- lib/isodoc/iso/metadata.rb
Constant Summary collapse
- PART_LABEL =
we don’t leave this to i18n.rb, because we have both English and French titles in the same document
{ en: "Part", fr: "Partie", ru: "Часть" }.freeze
- AMD_LABEL =
{ en: "AMENDMENT", fr: "AMENDMENT", ru: "ПОПРАВКА" }.freeze
- ADD_LABEL =
{ en: "ADDENDUM", fr: "ADDITIF", ru: "ДОПОЛНЕНИЕ" }.freeze
- CORR_LABEL =
{ en: "TECHNICAL CORRIGENDUM", fr: "RECTIFICATIF TECHNIQUE", ru: "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ" }.freeze
Instance Method Summary collapse
- #add_prefix(titlenums, lang) ⇒ Object
- #amd_prefix(titlenums, lang) ⇒ Object
- #author(xml, _out) ⇒ Object
- #compose_title(tparts, tnums, lang) ⇒ Object
- #corr_prefix(titlenums, lang) ⇒ Object
- #docid(isoxml, _out) ⇒ Object
- #docstatus(isoxml, _out) ⇒ Object
- #docstatus1(isoxml, docstatus) ⇒ Object
- #doctype(isoxml, _out) ⇒ Object
- #editorialgroup(xml) ⇒ Object
-
#initialize(lang, script, locale, i18n) ⇒ Metadata
constructor
A new instance of Metadata.
- #part_prefix(titlenums, lang) ⇒ Object
- #part_title(part, titlenums, lang) ⇒ Object
- #sc(xml) ⇒ Object
- #sc_base(xml, grouptype) ⇒ Object
- #secretariat(xml) ⇒ Object
- #status_abbrev(stage, _substage, iter, draft, doctype) ⇒ Object
- #subtitle(isoxml, _out) ⇒ Object
- #tc(xml) ⇒ Object
- #tc_base(xml, grouptype) ⇒ Object
- #title(isoxml, _out) ⇒ Object
- #title_nums(isoxml) ⇒ Object
- #title_parts(isoxml, lang) ⇒ Object
- #unpublished(status) ⇒ Object
- #wg(xml) ⇒ Object
- #wg_base(xml, grouptype) ⇒ Object
Constructor Details
#initialize(lang, script, locale, i18n) ⇒ Metadata
6 7 8 9 10 11 |
# File 'lib/isodoc/iso/metadata.rb', line 6 def initialize(lang, script, locale, i18n) super DATETYPES.each { |w| ["#{w.gsub(/-/, '_')}date".to_sym] = nil } set(:obsoletes, nil) set(:obsoletes_part, nil) end |
Instance Method Details
#add_prefix(titlenums, lang) ⇒ Object
96 97 98 |
# File 'lib/isodoc/iso/metadata.rb', line 96 def add_prefix(titlenums, lang) "#{self.class::ADD_LABEL[lang.to_sym]} #{titlenums[:add]}" end |
#amd_prefix(titlenums, lang) ⇒ Object
92 93 94 |
# File 'lib/isodoc/iso/metadata.rb', line 92 def amd_prefix(titlenums, lang) "#{self.class::AMD_LABEL[lang.to_sym]} #{titlenums[:amd]}" end |
#author(xml, _out) ⇒ Object
176 177 178 179 180 181 182 183 |
# File 'lib/isodoc/iso/metadata.rb', line 176 def (xml, _out) super tc(xml) sc(xml) wg(xml) editorialgroup(xml) secretariat(xml) end |
#compose_title(tparts, tnums, lang) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/isodoc/iso/metadata.rb', line 104 def compose_title(tparts, tnums, lang) t = tparts[:main].nil? ? "" : to_xml(tparts[:main].children) tparts[:intro] and t = "#{to_xml(tparts[:intro].children)} — #{t}" tparts[:complementary] and t = "#{t} — #{to_xml(tparts[:complementary].children)}" if tparts[:part] suffix = part_title(tparts[:part], tnums, lang) t = "#{t} — #{suffix}" end t end |
#corr_prefix(titlenums, lang) ⇒ Object
100 101 102 |
# File 'lib/isodoc/iso/metadata.rb', line 100 def corr_prefix(titlenums, lang) "#{self.class::CORR_LABEL[lang.to_sym]} #{titlenums[:corr]}" end |
#docid(isoxml, _out) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/isodoc/iso/metadata.rb', line 54 def docid(isoxml, _out) set(:tc_docnumber, isoxml .xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']")).map(&:text)) { docnumber: "ISO", docnumber_lang: "iso-with-lang", docnumber_reference: "iso-reference", docnumber_undated: "iso-undated" }.each do |k, v| set(k, isoxml&.at(ns("//bibdata/docidentifier[@type = '#{v}']"))&.text) end end |
#docstatus(isoxml, _out) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/iso/metadata.rb', line 24 def docstatus(isoxml, _out) docstatus = isoxml.at(ns("//bibdata/status/stage")) published_default(isoxml) revdate = isoxml.at(ns("//bibdata/version/revision-date")) set(:revdate, revdate&.text) docstatus and docstatus1(isoxml, docstatus) docscheme = isoxml.at(ns("//presentation-metadata[name" \ "[text() = 'document-scheme']]/value")) docscheme and set(:document_scheme, docscheme.text) end |
#docstatus1(isoxml, docstatus) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/isodoc/iso/metadata.rb', line 35 def docstatus1(isoxml, docstatus) set(:stage, docstatus.text) set(:stage_int, docstatus.text.to_i) set(:substage_int, isoxml.at(ns("//bibdata/status/substage"))&.text) set(:unpublished, unpublished(docstatus.text)) set(:statusabbr, status_abbrev(docstatus["abbreviation"] || "??", isoxml.at(ns("//bibdata/status/substage"))&.text, isoxml.at(ns("//bibdata/status/iteration"))&.text, isoxml.at(ns("//bibdata/version/draft"))&.text, isoxml.at(ns("//bibdata/ext/doctype"))&.text)) unpublished(docstatus.text) and set(:stageabbr, docstatus["abbreviation"]) end |
#doctype(isoxml, _out) ⇒ Object
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/isodoc/iso/metadata.rb', line 246 def doctype(isoxml, _out) super ics = isoxml.xpath(ns("//bibdata/ext/ics/code")) .each_with_object([]) { |i, m| m << i.text } set(:ics, ics.empty? ? nil : ics.join(", ")) a = isoxml.at(ns("//bibdata/ext/horizontal")) and set(:horizontal, a.text) a = isoxml.at(ns("//bibdata/ext/fast-track")) and set(:fast_track, a.text) end |
#editorialgroup(xml) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/isodoc/iso/metadata.rb', line 227 def editorialgroup(xml) xpath = " //contributor[role/@type = 'author'][role/description = 'Technical committee']/organization/subdivision/identifier[@type = 'full']\n XPATH\n a = xml.xpath(ns(xpath))\n a.empty? or set(:editorialgroup,\n connectives_strip(@i18n.boolean_conj(a.map(&:text),\n \"and\")))\n a = xml.xpath(ns(xpath.sub(\"author\", \"authorizer\")))\n a.empty? or set(:approvalgroup,\n connectives_strip(@i18n.boolean_conj(a.map(&:text),\n \"and\")))\nend\n" |
#part_prefix(titlenums, lang) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/isodoc/iso/metadata.rb', line 85 def part_prefix(titlenums, lang) p = titlenums[:part] titlenums[:part] && titlenums[:subpart] and p = "#{titlenums[:part]}–#{titlenums[:subpart]}" "#{self.class::PART_LABEL[lang.to_sym]} #{p}" end |
#part_title(part, titlenums, lang) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/isodoc/iso/metadata.rb', line 74 def part_title(part, titlenums, lang) part or return "" suffix = to_xml(part.children) p = titlenums[:part] titlenums[:part] && titlenums[:subpart] and p = "#{titlenums[:part]}–#{titlenums[:subpart]}" titlenums[:part] and suffix = "#{PART_LABEL[lang.to_sym]} #{p}: " + suffix suffix end |
#sc(xml) ⇒ Object
199 200 201 202 |
# File 'lib/isodoc/iso/metadata.rb', line 199 def sc(xml) scid = sc_base(xml, "editorialgroup") or return set(:sc, scid) end |
#sc_base(xml, grouptype) ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/isodoc/iso/metadata.rb', line 204 def sc_base(xml, grouptype) sc_num = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/" \ "@number")) or return nil sc_type = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/" \ "@type"))&.text || "SC" sc_type == "Other" and sc_type = "" "#{sc_type} #{sc_num.text}" end |
#secretariat(xml) ⇒ Object
241 242 243 244 |
# File 'lib/isodoc/iso/metadata.rb', line 241 def secretariat(xml) sec = xml.at(ns("//bibdata/ext/editorialgroup/secretariat")) set(:secretariat, sec.text) if sec end |
#status_abbrev(stage, _substage, iter, draft, doctype) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/isodoc/iso/metadata.rb', line 13 def status_abbrev(stage, _substage, iter, draft, doctype) stage or return "" if %w(technical-report technical-specification).include?(doctype) stage = "DTS" if stage == "DIS" stage = "FDTS" if stage == "FDIS" end %w(PWI NWIP WD CD).include?(stage) && iter and stage += iter stage = "Pre#{stage}" if /^0\./.match?(draft) stage end |
#subtitle(isoxml, _out) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/isodoc/iso/metadata.rb', line 156 def subtitle(isoxml, _out) lang = @lang == "en" ? "fr" : "en" tp = title_parts(isoxml, lang) tn = title_nums(isoxml) set(:docsubtitlemain, tp[:main] ? to_xml(tp[:main].children) : "") main = compose_title(tp, tn, lang) set(:docsubtitle, main) tp[:intro] and set(:docsubtitleintro, to_xml(tp[:intro].children)) tp[:complementary] and set(:docsubtitlecomplementary, to_xml(tp[:complementary].children)) set(:docsubtitlepartlabel, part_prefix(tn, lang)) tp[:part] and set(:docsubtitlepart, to_xml(tp[:part].children)) set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd] set(:docsubtitleamd, to_xml(tp[:amd].children)) if tp[:amd] set(:docsubtitleaddlabel, add_prefix(tn, lang)) if tn[:add] set(:docsubtitleadd, to_xml(tp[:add].children)) if tp[:add] set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr] end |
#tc(xml) ⇒ Object
185 186 187 188 |
# File 'lib/isodoc/iso/metadata.rb', line 185 def tc(xml) tcid = tc_base(xml, "editorialgroup") or return set(:tc, tcid) end |
#tc_base(xml, grouptype) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/isodoc/iso/metadata.rb', line 190 def tc_base(xml, grouptype) tc_num = xml.at(ns("//bibdata/ext/#{grouptype}/" \ "technical-committee/@number")) or return nil tc_type = xml.at(ns("//bibdata/ext/#{grouptype}/technical-committee/" \ "@type"))&.text || "TC" tc_type == "Other" and tc_type = "" "#{tc_type} #{tc_num.text}".strip end |
#title(isoxml, _out) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/iso/metadata.rb', line 133 def title(isoxml, _out) lang = case @lang when "fr", "ru" then @lang else "en" end # intro, main, complementary, part, amd = title_parts(isoxml, lang) tp = title_parts(isoxml, lang) tn = title_nums(isoxml) set(:doctitlemain, tp[:main] ? to_xml(tp[:main].children) : "") main = compose_title(tp, tn, lang) set(:doctitle, main) tp[:intro] and set(:doctitleintro, to_xml(tp[:intro].children)) tp[:complementary] and set(:doctitlecomplementary, to_xml(tp[:complementary].children)) set(:doctitlepartlabel, part_prefix(tn, lang)) set(:doctitlepart, to_xml(tp[:part].children)) if tp[:part] set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd] set(:doctitleamd, to_xml(tp[:amd].children)) if tp[:amd] set(:doctitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr] set(:doctitleaddlabel, add_prefix(tn, lang)) if tn[:add] set(:doctitleadd, to_xml(tp[:add].children)) if tp[:add] end |
#title_nums(isoxml) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/iso/metadata.rb', line 117 def title_nums(isoxml) prefix = "//bibdata/ext/structuredidentifier/project-number" { part: isoxml.at(ns("#{prefix}/@part")), subpart: isoxml.at(ns("#{prefix}/@subpart")), amd: isoxml.at(ns("#{prefix}/@amendment")), add: isoxml.at(ns("#{prefix}/@addendum")), corr: isoxml.at(ns("#{prefix}/@corrigendum")) } end |
#title_parts(isoxml, lang) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/isodoc/iso/metadata.rb', line 126 def title_parts(isoxml, lang) %w(intro main complementary part amd add).each_with_object({}) do |w, m| m[w.to_sym] = isoxml.at(ns("//bibdata/title[@type='title-#{w}' and " \ "@language='#{lang}']")) end end |
#unpublished(status) ⇒ Object
50 51 52 |
# File 'lib/isodoc/iso/metadata.rb', line 50 def unpublished(status) status.to_i.positive? && status.to_i < 60 end |
#wg(xml) ⇒ Object
213 214 215 216 |
# File 'lib/isodoc/iso/metadata.rb', line 213 def wg(xml) wgid = wg_base(xml, "editorialgroup") or return set(:wg, wgid) end |
#wg_base(xml, grouptype) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/isodoc/iso/metadata.rb', line 218 def wg_base(xml, grouptype) wg_num = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/" \ "@number")) or return wg_type = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/" \ "@type"))&.text || "WG" wg_type == "Other" and wg_type = "" "#{wg_type} #{wg_num.text}" end |