Class: IsoDoc::Metadata
- Inherits:
-
Object
- Object
- IsoDoc::Metadata
- Defined in:
- lib/isodoc/metadata.rb
Constant Summary collapse
- DATETYPES =
%w{published accessed created implemented obsoleted confirmed updated issued received transmitted copied unchanged circulated}.freeze
Instance Method Summary collapse
- #agency(xml) ⇒ Object
- #author(xml, _out) ⇒ Object
- #bibdate(isoxml, _out) ⇒ Object
- #docid(isoxml, _out) ⇒ Object
- #docstatus(isoxml, _out) ⇒ Object
- #doctype(isoxml, _out) ⇒ Object
- #draftinfo(draft, revdate) ⇒ Object
- #extract_person_affiliations(authors) ⇒ Object
- #extract_person_names(authors) ⇒ Object
- #extract_person_names_affiliations(authors) ⇒ Object
- #get ⇒ Object
-
#initialize(lang, script, labels) ⇒ Metadata
constructor
A new instance of Metadata.
- #iso?(org) ⇒ Boolean
- #ns(xpath) ⇒ Object
- #personal_authors(isoxml) ⇒ Object
- #relations(isoxml, _out) ⇒ Object
- #relations_obsoletes(isoxml) ⇒ Object
- #relations_partof(isoxml) ⇒ Object
- #sc(xml) ⇒ Object
- #secretariat(xml) ⇒ Object
- #set(key, value) ⇒ Object
- #status_print(status) ⇒ Object
- #subtitle(isoxml, _out) ⇒ Object
- #tc(xml) ⇒ Object
- #title(isoxml, _out) ⇒ Object
- #unpublished(status) ⇒ Object
- #url(xml, _out) ⇒ Object
- #version(isoxml, _out) ⇒ Object
- #wg(xml) ⇒ Object
Constructor Details
#initialize(lang, script, labels) ⇒ Metadata
Returns a new instance of Metadata.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/isodoc/metadata.rb', line 10 def initialize(lang, script, labels) @metadata = { tc: "XXXX", sc: "XXXX", wg: "XXXX", editorialgroup: [], secretariat: "XXXX", obsoletes: nil, obsoletes_part: nil } DATETYPES.each { |w| @metadata["#{w}date".to_sym] = "XXX" } @lang = lang @script = script @c = HTMLEntities.new @labels = labels end |
Instance Method Details
#agency(xml) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/isodoc/metadata.rb', line 146 def agency(xml) agency = "" xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\ "organization")).each do |org| name = org&.at(ns("./name"))&.text abbrev = org&.at(ns("./abbreviation"))&.text agency1 = abbrev || name agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/" end set(:agency, agency.sub(%r{/$}, "")) end |
#author(xml, _out) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/isodoc/metadata.rb', line 78 def (xml, _out) (xml) tc(xml) sc(xml) wg(xml) secretariat(xml) agency(xml) end |
#bibdate(isoxml, _out) ⇒ Object
123 124 125 126 127 |
# File 'lib/isodoc/metadata.rb', line 123 def bibdate(isoxml, _out) isoxml.xpath(ns("//bibdata/date")).each do |d| set("#{d['type']}date".to_sym, Common::date_range(d)) end end |
#docid(isoxml, _out) ⇒ Object
175 176 177 178 |
# File 'lib/isodoc/metadata.rb', line 175 def docid(isoxml, _out) dn = isoxml.at(ns("//bibdata/docidentifier")) set(:docnumber, dn&.text) end |
#docstatus(isoxml, _out) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/metadata.rb', line 158 def docstatus(isoxml, _out) docstatus = isoxml.at(ns("//bibdata/status")) set(:unpublished, true) if docstatus set(:status, status_print(docstatus.text)) set(:unpublished, unpublished(docstatus.text)) end end |
#doctype(isoxml, _out) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/isodoc/metadata.rb', line 129 def doctype(isoxml, _out) b = isoxml.at(ns("//bibdata")) || return return unless b["type"] t = b["type"].split(/[- ]/).map{ |w| w.capitalize }.join(" ") set(:doctype, t) ics = [] isoxml.xpath(ns("//bibdata/ics/code")).each { |i| ics << i.text } set(:ics, ics.empty? ? "XXX" : ics.join(", ")) end |
#draftinfo(draft, revdate) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/isodoc/metadata.rb', line 180 def draftinfo(draft, revdate) draftinfo = "" if draft draftinfo = " (#{@labels["draft_label"]} #{draft}" draftinfo += ", #{revdate}" if revdate draftinfo += ")" end IsoDoc::Function::I18n::l10n(draftinfo, @lang, @script) end |
#extract_person_affiliations(authors) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/isodoc/metadata.rb', line 49 def extract_person_affiliations() .inject([]) do |m, a| name = a&.at(ns("./affiliation/organization/name"))&.text location = a&.at(ns("./affiliation/organization/address/"\ "formattedAddress"))&.text m << ((!name.nil? && !location.nil?) ? "#{name}, #{location}" : (name || location || "")) m end end |
#extract_person_names(authors) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/isodoc/metadata.rb', line 35 def extract_person_names() .inject([]) do |ret, a| if a.at(ns("./name/completename")) ret << a.at(ns("./name/completename")).text else fn = [] forenames = a.xpath(ns("./name/forename")) forenames.each { |f| fn << f.text } surname = a&.at(ns("./name/surname"))&.text ret << fn.join(" ") + " " + surname end end end |
#extract_person_names_affiliations(authors) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/isodoc/metadata.rb', line 60 def extract_person_names_affiliations() names = extract_person_names() affils = extract_person_affiliations() ret = {} affils.each_with_index do |a, i| ret[a] ||= [] ret[a] << names[i] end ret end |
#get ⇒ Object
27 28 29 |
# File 'lib/isodoc/metadata.rb', line 27 def get @metadata end |
#iso?(org) ⇒ Boolean
139 140 141 142 143 144 |
# File 'lib/isodoc/metadata.rb', line 139 def iso?(org) name = org&.at(ns("./name"))&.text abbrev = org&.at(ns("./abbreviation"))&.text (abbrev == "ISO" || name == "International Organization for Standardization" ) end |
#ns(xpath) ⇒ Object
6 7 8 |
# File 'lib/isodoc/metadata.rb', line 6 def ns(xpath) Common::ns(xpath) end |
#personal_authors(isoxml) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/isodoc/metadata.rb', line 71 def (isoxml) = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\ "or xmlns:role/@type = 'editor']/person")) set(:authors, extract_person_names()) set(:authors_affiliations, extract_person_names_affiliations()) end |
#relations(isoxml, _out) ⇒ Object
208 209 210 211 |
# File 'lib/isodoc/metadata.rb', line 208 def relations(isoxml, _out) relations_obsoletes(isoxml) relations_partof(isoxml) end |
#relations_obsoletes(isoxml) ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/isodoc/metadata.rb', line 219 def relations_obsoletes(isoxml) std = isoxml.at(ns("//bibdata/relation[@type = 'obsoletes']")) || return locality = std.at(ns(".//locality")) id = std.at(ns(".//docidentifier")) set(:obsoletes, id.text) if id set(:obsoletes_part, locality.text) if locality end |
#relations_partof(isoxml) ⇒ Object
213 214 215 216 217 |
# File 'lib/isodoc/metadata.rb', line 213 def relations_partof(isoxml) std = isoxml.at(ns("//bibdata/relation[@type = 'partOf']")) || return id = std.at(ns(".//docidentifier")) set(:partof, id.text) if id end |
#sc(xml) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/metadata.rb', line 98 def sc(xml) sc_num = xml.at(ns("//bibdata/editorialgroup/subcommittee/@number")) sc_type = xml.at(ns("//bibdata/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
118 119 120 121 |
# File 'lib/isodoc/metadata.rb', line 118 def secretariat(xml) sec = xml.at(ns("//bibdata/editorialgroup/secretariat")) set(:secretariat, sec.text) if sec end |
#set(key, value) ⇒ Object
31 32 33 |
# File 'lib/isodoc/metadata.rb', line 31 def set(key, value) @metadata[key] = value end |
#status_print(status) ⇒ Object
171 172 173 |
# File 'lib/isodoc/metadata.rb', line 171 def status_print(status) status.split(/-/).map{ |w| w.capitalize }.join(" ") end |
#subtitle(isoxml, _out) ⇒ Object
204 205 206 |
# File 'lib/isodoc/metadata.rb', line 204 def subtitle(isoxml, _out) nil end |
#tc(xml) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/metadata.rb', line 87 def tc(xml) tc_num = xml.at(ns("//bibdata/editorialgroup/technical-committee/@number")) tc_type = xml.at(ns("//bibdata/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
199 200 201 202 |
# File 'lib/isodoc/metadata.rb', line 199 def title(isoxml, _out) main = isoxml&.at(ns("//bibdata/title[@language='en']"))&.text set(:doctitle, main) end |
#unpublished(status) ⇒ Object
167 168 169 |
# File 'lib/isodoc/metadata.rb', line 167 def unpublished(status) !(status.downcase == "published") end |
#url(xml, _out) ⇒ Object
227 228 229 230 231 232 233 |
# File 'lib/isodoc/metadata.rb', line 227 def url(xml, _out) a = xml.at(ns("//bibdata/uri[not(@type)]")) and set(:url, a.text) a = xml.at(ns("//bibdata/uri[@type = 'html']")) and set(:html, a.text) a = xml.at(ns("//bibdata/uri[@type = 'xml']")) and set(:xml, a.text) a = xml.at(ns("//bibdata/uri[@type = 'pdf']")) and set(:pdf, a.text) a = xml.at(ns("//bibdata/uri[@type = 'doc']")) and set(:doc, a.text) end |
#version(isoxml, _out) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/isodoc/metadata.rb', line 190 def version(isoxml, _out) set(:edition, isoxml&.at(ns("//bibdata/edition"))&.text) set(:docyear, isoxml&.at(ns("//bibdata/copyright/from"))&.text) set(:draft, isoxml&.at(ns("//version/draft"))&.text) set(:revdate, isoxml&.at(ns("//version/revision-date"))&.text) set(:draftinfo, draftinfo(get[:draft], get[:revdate])) end |
#wg(xml) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/metadata.rb', line 108 def wg(xml) wg_num = xml.at(ns("//bibdata/editorialgroup/workgroup/@number")) wg_type = xml.at(ns("//bibdata/editorialgroup/workgroup/@type"))&.text || "WG" if wg_num wgid = "#{wg_type} #{wg_num.text}" set(:wg, wgid) set(:editorialgroup, get[:editorialgroup] << wgid) end end |