Class: IsoDoc::Iso::Metadata
- Inherits:
-
Metadata
- Object
- Metadata
- IsoDoc::Iso::Metadata
- Defined in:
- lib/isodoc/iso/metadata.rb
Constant Summary collapse
- COMMITTEE =
"//bibdata/contributor[role/@type = 'author'] " \ "[role/description = 'committee']/organization".freeze
Instance Method Summary collapse
- #author(xml, _out) ⇒ Object
- #compose_title(tparts, tnums, lang) ⇒ Object
- #docid(isoxml, _out) ⇒ Object
- #docstatus(isoxml, _out) ⇒ Object
- #docstatus1(isoxml, docstatus, published) ⇒ Object
- #doctype(isoxml, _out) ⇒ Object
- #editorialgroup(xml) ⇒ Object
-
#initialize(lang, script, locale, i18n) ⇒ Metadata
constructor
A new instance of Metadata.
- #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_part_prefix(xml, part, lang) ⇒ Object
- #title_parts(isoxml, lang) ⇒ Object
- #wg(xml) ⇒ Object
- #wg_base(xml, _grouptype) ⇒ Object
Constructor Details
#initialize(lang, script, locale, i18n) ⇒ Metadata
Returns a new instance of 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| @metadata[:"#{w.gsub('-', '_')}date"] = nil } set(:obsoletes, nil) set(:obsoletes_part, nil) end |
Instance Method Details
#author(xml, _out) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/isodoc/iso/metadata.rb', line 167 def (xml, _out) super tc(xml) sc(xml) wg(xml) editorialgroup(xml) secretariat(xml) end |
#compose_title(tparts, tnums, lang) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/isodoc/iso/metadata.rb', line 76 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 |
#docid(isoxml, _out) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/iso/metadata.rb', line 48 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 = published_default(isoxml) revdate = isoxml.at(ns("//bibdata/date[@type='updated']")) set(:revdate, revdate&.text) docstatus and docstatus1(isoxml, docstatus, published) docscheme = get[:"presentation_metadata_document-scheme"] docscheme && !docscheme.empty? and set(:document_scheme, docscheme.first) end |
#docstatus1(isoxml, docstatus, published) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/isodoc/iso/metadata.rb', line 35 def docstatus1(isoxml, docstatus, published) set(:stage, docstatus.text) set(:stage_int, docstatus.text.to_i) set(:substage_int, isoxml.at(ns("//bibdata/status/substage"))&.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"))&.text, isoxml.at(ns("//bibdata/ext/doctype"))&.text)) !published and set(:stageabbr, docstatus["abbreviation"]) end |
#doctype(isoxml, _out) ⇒ Object
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/isodoc/iso/metadata.rb', line 231 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
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/isodoc/iso/metadata.rb', line 212 def editorialgroup(xml) xpath = "#{COMMITTEE}/subdivision/identifier[@type = 'full']" a = xml.xpath(ns(xpath)) a.empty? or set(:editorialgroup, connectives_strip(@i18n.boolean_conj(a.map(&:text), "and"))) a = xml.xpath(ns(xpath.sub("author", "authorizer"))) a.empty? or set(:approvalgroup, connectives_strip(@i18n.boolean_conj(a.map(&:text), "and"))) end |
#part_title(part, titlenums, lang) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/isodoc/iso/metadata.rb', line 59 def part_title(part, titlenums, lang) part or return "" suffix = to_xml(part.children) if titlenums[:part] && t = title_part_prefix(titlenums[:part].document.root, "part", lang) i = IsoDoc::I18n.new(lang, ::Metanorma::Utils.default_script(lang)) suffix = i.l10n("<esc>#{t}</esc>: <esc>#{suffix}</esc>") end suffix end |
#sc(xml) ⇒ Object
190 191 192 193 |
# File 'lib/isodoc/iso/metadata.rb', line 190 def sc(xml) scid = sc_base(xml, "editorialgroup") or return set(:sc, scid) end |
#sc_base(xml, _grouptype) ⇒ Object
195 196 197 198 199 |
# File 'lib/isodoc/iso/metadata.rb', line 195 def sc_base(xml, _grouptype) s = xml.at(ns("#{COMMITTEE}/subdivision[@type = 'Subcommittee']")) s or return nil s.at(ns("./identifier[not(@type = 'full')]"))&.text end |
#secretariat(xml) ⇒ Object
224 225 226 227 228 229 |
# File 'lib/isodoc/iso/metadata.rb', line 224 def secretariat(xml) sec = xml.at(ns("//bibdata/contributor[role/@type = 'author']" \ "[role/description = 'secretariat']/organization/subdivision" \ "[@type = 'Secretariat']/name")) 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
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/iso/metadata.rb', line 138 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) : "") tp[:intro] and set(:docsubtitleintro, to_xml(tp[:intro].children)) tp[:complementary] and set(:docsubtitlecomplementary, to_xml(tp[:complementary].children)) set(:docsubtitlepartlabel, title_part_prefix(isoxml, "part", lang)) tp[:part] and set(:docsubtitlepart, to_xml(tp[:part].children)) tn[:amd] and set(:docsubtitleamdlabel, title_part_prefix(isoxml, "amendment", lang)) tp[:amd] and set(:docsubtitleamd, to_xml(tp[:amd].children)) tn[:add] and set(:docsubtitleaddlabel, title_part_prefix(isoxml, "addendum", lang)) tp[:add] and set(:docsubtitleadd, to_xml(tp[:add].children)) tn[:sup] and set(:docsubtitlesuplabel, title_part_prefix(isoxml, "supplement", lang)) tp[:sup] and set(:docsubtitlesup, to_xml(tp[:sup].children)) tn[:ext] and set(:docsubtitleextlabel, title_part_prefix(isoxml, "extract", lang)) tp[:ext] and set(:docsubtitleext, to_xml(tp[:ext].children)) tn[:corr] and set(:docsubtitlecorrlabel, title_part_prefix(isoxml, "corrigendum", lang)) main = compose_title(tp, tn, lang) set(:docsubtitle, main) end |
#tc(xml) ⇒ Object
176 177 178 179 |
# File 'lib/isodoc/iso/metadata.rb', line 176 def tc(xml) tcid = tc_base(xml, "editorialgroup") or return set(:tc, tcid) end |
#tc_base(xml, _grouptype) ⇒ Object
184 185 186 187 188 |
# File 'lib/isodoc/iso/metadata.rb', line 184 def tc_base(xml, _grouptype) s = xml.at(ns("#{COMMITTEE}/subdivision[@type = 'Technical committee']")) s or return nil s.at(ns("./identifier[not(@type = 'full')]"))&.text end |
#title(isoxml, _out) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/isodoc/iso/metadata.rb', line 107 def title(isoxml, _out) lang = case @lang when "fr", "ru" then @lang else "en" end tp = title_parts(isoxml, lang) tn = title_nums(isoxml) set(:doctitlemain, tp[:main] ? to_xml(tp[:main].children) : "") tp[:intro] and set(:doctitleintro, to_xml(tp[:intro].children)) tp[:complementary] and set(:doctitlecomplementary, to_xml(tp[:complementary].children)) set(:doctitlepartlabel, title_part_prefix(isoxml, "part", lang)) tp[:part] and set(:doctitlepart, to_xml(tp[:part].children)) tn[:amd] and set(:doctitleamdlabel, title_part_prefix(isoxml, "amendment", lang)) tp[:amd] and set(:doctitleamd, to_xml(tp[:amd].children)) tn[:corr] and set(:doctitlecorrlabel, title_part_prefix(isoxml, "corrigendum", lang)) tn[:add] and set(:doctitleaddlabel, title_part_prefix(isoxml, "addendum", lang)) tp[:add] and set(:doctitleadd, to_xml(tp[:add].children)) tn[:sup] and set(:doctitlesuplabel, title_part_prefix(isoxml, "supplement", lang)) tp[:sup] and set(:doctitlesup, to_xml(tp[:sup].children)) tn[:ext] and set(:doctitleextlabel, title_part_prefix(isoxml, "extract", lang)) tp[:ext] and set(:doctitleext, to_xml(tp[:ext].children)) main = compose_title(tp, tn, lang) set(:doctitle, main) end |
#title_nums(isoxml) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/isodoc/iso/metadata.rb', line 89 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")), sup: isoxml.at(ns("#{prefix}/@supplement")), ext: isoxml.at(ns("#{prefix}/@extract")), corr: isoxml.at(ns("#{prefix}/@corrigendum")) } end |
#title_part_prefix(xml, part, lang) ⇒ Object
70 71 72 73 74 |
# File 'lib/isodoc/iso/metadata.rb', line 70 def title_part_prefix(xml, part, lang) t = xml.at(ns("//bibdata/title[@language='#{lang}']" \ "[@type='title-#{part}-prefix']")) or return to_xml(t.children) end |
#title_parts(isoxml, lang) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/isodoc/iso/metadata.rb', line 100 def title_parts(isoxml, lang) %w(intro main complementary part amd add sup ext).each_with_object({}) do |w, m| m[w.to_sym] = isoxml.at(ns("//bibdata/title[@type='title-#{w}' and " \ "@language='#{lang}']")) end end |
#wg(xml) ⇒ Object
201 202 203 204 |
# File 'lib/isodoc/iso/metadata.rb', line 201 def wg(xml) wgid = wg_base(xml, "editorialgroup") or return set(:wg, wgid) end |
#wg_base(xml, _grouptype) ⇒ Object
206 207 208 209 210 |
# File 'lib/isodoc/iso/metadata.rb', line 206 def wg_base(xml, _grouptype) s = xml.at(ns("#{COMMITTEE}/subdivision[@type = 'Workgroup']")) s or return nil s.at(ns("./identifier[not(@type = 'full')]"))&.text end |