Class: IsoDoc::NIST::Metadata
- Inherits:
-
Metadata
- Object
- Metadata
- IsoDoc::NIST::Metadata
- Defined in:
- lib/isodoc/nist/metadata.rb,
lib/isodoc/nist/metadata_id.rb
Instance Method Summary collapse
- #author(ixml, _out) ⇒ Object
- #bibdate(ixml, _out) ⇒ Object
- #commentperiod(ixml, _out) ⇒ Object
- #daterange_proc(val, format) ⇒ Object
- #docid(ixml, _out) ⇒ Object
- #docstatus(ixml, _out) ⇒ Object
- #draft_prefix(ixml) ⇒ Object
- #draftinfo(draft, revdate) ⇒ Object
-
#initialize(lang, script, labels) ⇒ Metadata
constructor
A new instance of Metadata.
- #iter_abbr(stage, iter) ⇒ Object
- #iter_code(ixml) ⇒ Object
- #iter_ordinal(ixml) ⇒ Object
- #mmddyyyy(isodate) ⇒ Object
- #most_recent_date(ixml) ⇒ Object
- #most_recent_date1(ixml) ⇒ Object
- #note(xml, _out) ⇒ Object
- #relations(ixml, _out) ⇒ Object
- #relations1(ixml, type) ⇒ Object
- #series(ixml, _out) ⇒ Object
- #stage_abbr(stage) ⇒ Object
- #status_abbr(stage, iter) ⇒ Object
- #status_print(status) ⇒ Object
- #stripdate(id) ⇒ Object
- #subtitle(ixml, _out) ⇒ Object
- #superseding_dates(newdoc) ⇒ Object
- #superseding_doc(ixml) ⇒ Object
- #superseding_iteration(newdoc) ⇒ Object
- #superseding_titles(ixml, newdoc) ⇒ Object
- #title(ixml, _out) ⇒ Object
- #unpublished(status) ⇒ Object
- #url(xml, _out) ⇒ Object
- #version(ixml, _out) ⇒ Object
- #withdrawal_pending(ixml) ⇒ Object
Constructor Details
#initialize(lang, script, labels) ⇒ Metadata
Returns a new instance of Metadata.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/nist/metadata.rb', line 8 def initialize(lang, script, labels) super here = File.join(File.dirname(__FILE__), "html") set(:logo_nist, File.(File.join(here, "logo.png"))) set(:logo_cswp, File.(File.join(here, "logo_cswp.png"))) set(:logo_commerce, File.(File.join(here, "commerce-logo-color.png"))) set(:logo_commerce_word, File.(File.join(here, "deptofcommerce.png"))) end |
Instance Method Details
#author(ixml, _out) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/isodoc/nist/metadata.rb', line 36 def (ixml, _out) tc = ixml.at(ns("//bibdata/ext/editorialgroup/committee")) set(:tc, tc.text.upcase) if tc subdiv = ixml.at(ns("//bibdata/contributor[role/@type = 'publisher']/"\ "organization/subdivision")) and set(:nist_subdiv, subdiv.text) super end |
#bibdate(ixml, _out) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/isodoc/nist/metadata.rb', line 54 def bibdate(ixml, _out) super ixml.xpath(ns("//bibdata/date")).each do |d| val = Common::date_range(d) next if val == "XXX" set("#{d['type']}date_monthyear".to_sym, daterange_proc(val, :monthyr)) set("#{d['type']}date_mmddyyyy".to_sym, daterange_proc(val, :mmddyyyy)) set("#{d['type']}date_MMMddyyyy".to_sym, daterange_proc(val, :MMMddyyyy)) end withdrawal_pending(ixml) most_recent_date(ixml) end |
#commentperiod(ixml, _out) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/isodoc/nist/metadata.rb', line 126 def commentperiod(ixml, _out) from = ixml.at(ns("//bibdata/ext/commentperiod/from"))&.text to = ixml.at(ns("//bibdata/ext/commentperiod/to"))&.text extended = ixml.at(ns("//bibdata/ext/commentperiod/extended"))&.text set(:comment_from, from) if from set(:comment_to, to) if to set(:comment_extended, extended) if extended end |
#daterange_proc(val, format) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/isodoc/nist/metadata.rb', line 96 def daterange_proc(val, format) m = /^(?<date1>[^&]+)(?<ndash>–)?(?<date2>.*)$/.match val val_monthyear = send(format, m[:date1]) val_monthyear += "–" if m[:ndash] val_monthyear += send(format, m[:date2]) unless m[:date2].empty? val_monthyear end |
#docid(ixml, _out) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/isodoc/nist/metadata_id.rb', line 74 def docid(ixml, _out) docid = ixml.at(ns("//bibdata/docidentifier[@type = 'NIST']"))&.text docid_long = ixml.at(ns("//bibdata/docidentifier[@type = 'nist-long']"))&.text set(:docidentifier, docid) set(:docidentifier_long, docid_long) set(:docidentifier_undated, stripdate(docid)) set(:docidentifier_long_undated, stripdate(docid_long)) d = draft_prefix(ixml) and set(:draft_prefix, d) d = iter_code(ixml) and set(:iteration_code, d) d = iter_ordinal(ixml) and set(:iteration_ordinal, d) end |
#docstatus(ixml, _out) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/isodoc/nist/metadata_id.rb', line 42 def docstatus(ixml, _out) docstatus = ixml.at(ns("//bibdata/status/stage"))&.text set(:unpublished, unpublished(docstatus)) substage = ixml.at(ns("//bibdata/status/substage"))&.text substage and set(:substage, substage) iter = ixml.at(ns("//bibdata/status/iteration"))&.text set(:iteration, iter) if iter set(:status, status_print(docstatus || "final")) set(:errata, true) if ixml.at(ns("//errata")) unpublished(docstatus) and set(:stageabbr, stage_abbr(docstatus)) end |
#draft_prefix(ixml) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/isodoc/nist/metadata_id.rb', line 91 def draft_prefix(ixml) docstatus = ixml.at(ns("//bibdata/status/stage"))&.text return nil unless docstatus && /^draft/.match(docstatus) iter = iter_code(ixml) prefix = "DRAFT " iter and prefix += "(#{iter}) " prefix end |
#draftinfo(draft, revdate) ⇒ Object
116 117 118 119 120 |
# File 'lib/isodoc/nist/metadata_id.rb', line 116 def draftinfo(draft, revdate) draftinfo = "" draft and draftinfo = " #{@labels["draft_label"]} #{draft}" @i18n.l10n(draftinfo, @lang, @script) end |
#iter_abbr(stage, iter) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/nist/metadata_id.rb', line 4 def iter_abbr(stage, iter) return "F" if iter&.downcase == "final" && %w(draft-wip draft-prelim draft-public draft-approval).include?(stage) case stage when "draft-wip", "draft-prelim", "dradt-internal", "draft-approval" iter || "" when "draft-public" iter ||= "1" iter == "1" ? "I" : iter else "" end end |
#iter_code(ixml) ⇒ Object
100 101 102 103 104 |
# File 'lib/isodoc/nist/metadata_id.rb', line 100 def iter_code(ixml) docstatus = ixml.at(ns("//bibdata/status/stage"))&.text iter = ixml.at(ns("//bibdata/status/iteration"))&.text status_abbr(docstatus, iter) end |
#iter_ordinal(ixml) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/isodoc/nist/metadata_id.rb', line 106 def iter_ordinal(ixml) docstatus = ixml.at(ns("//bibdata/status/stage"))&.text iter = ixml.at(ns("//bibdata/status/iteration"))&.text iter ||= "1" if docstatus == "draft-public" return if iter.nil? return "Initial" if iter == "1" && docstatus == "draft-public" return "Final" if iter.downcase == "final" iter.to_i.localize.to_rbnf_s("SpelloutRules", "spellout-ordinal") end |
#mmddyyyy(isodate) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/isodoc/nist/metadata.rb', line 119 def mmddyyyy(isodate) return nil if isodate.nil? isodate += "-01" if /^\d\d\d\d-\d\d$/.match?(isodate) Date.parse(isodate).strftime("%m-%d-%Y") end |
#most_recent_date(ixml) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/isodoc/nist/metadata.rb', line 68 def most_recent_date(ixml) date = most_recent_date1(ixml) || return val = Common::date_range(date) return if val == "XXX" set(:most_recent_date_monthyear, daterange_proc(val, :monthyr)) set(:most_recent_date_mmddyyyy, daterange_proc(val, :mmddyyyy)) set(:most_recent_date_MMMddyyyy, daterange_proc(val, :MMMddyyyy)) end |
#most_recent_date1(ixml) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/isodoc/nist/metadata.rb', line 78 def most_recent_date1(ixml) docstatus = ixml.at(ns("//bibdata/status/stage"))&.text if /^draft/.match?(docstatus) (ixml.at(ns("//bibdata/date[@type = 'circulated']")) || ixml.at(ns("//version/revision-date"))) else ixml.at(ns("//bibdata/date[@type = 'issued']")) end end |
#note(xml, _out) ⇒ Object
236 237 238 239 240 241 242 243 244 |
# File 'lib/isodoc/nist/metadata.rb', line 236 def note(xml, _out) note = xml.at(ns("//bibdata/note[@type = 'additional-note']"))&.text and set(:additional_note, note) note = xml.at(ns("//bibdata/note[@type = 'withdrawal-note']"))&.text and set(:withdrawal_note, note) note = xml.at(ns("//bibdata/note[@type = 'withdrawal-announcement-link']"))&.text and set(:withdrawal_announcement_link, note) super end |
#relations(ixml, _out) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/isodoc/nist/metadata.rb', line 154 def relations(ixml, _out) ret = relations1(ixml, "obsoletes") set(:obsoletes, ret) unless ret.empty? ret = relations1(ixml, "obsoletedBy") set(:obsoletedby, ret) unless ret.empty? ret = relations1(ixml, "supersedes") set(:supersedes, ret) unless ret.empty? ret = relations1(ixml, "supersededBy") set(:supersededby, ret) unless ret.empty? superseding_doc(ixml) end |
#relations1(ixml, type) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/nist/metadata.rb', line 143 def relations1(ixml, type) ret = [] ixml.xpath(ns("//bibdata/relation[@type = '#{type}']"\ "[not(xmlns:description)] | "\ "//bibdata/relation[description = '#{type}']")) .each do |x| id = x&.at(ns(".//docidentifier"))&.text and ret << id end ret end |
#series(ixml, _out) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/isodoc/nist/metadata.rb', line 104 def series(ixml, _out) series = ixml.at(ns("//bibdata/series[@type = 'main']/title"))&.text and set(:series, series) seriesabbr = ixml.at(ns("//bibdata/series[@type = 'main']/abbreviation"))&.text set(:seriesabbr, seriesabbr) if seriesabbr subs = ixml.at(ns("//bibdata/series[@type = 'secondary']/title"))&.text abbr = ixml.at(ns("//bibdata/series[@type = 'secondary']/abbreviation"))&.text if seriesabbr == "NIST CSTS" subs and set(:series, subs) abbr and set(:seriesabbr, abbr) else subs and set(:subseries, subs) abbr and set(:subseriesabbr, abbr) end end |
#stage_abbr(stage) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/isodoc/nist/metadata_id.rb', line 18 def stage_abbr(stage) case stage when "draft-internal" then "ID" when "draft-wip" then "WD" when "draft-prelim" then "PreD" when "draft-public" then "PD" when "draft-approval" then "AD" else nil end end |
#status_abbr(stage, iter) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/isodoc/nist/metadata_id.rb', line 30 def status_abbr(stage, iter) case stage when "draft-internal" then "#{iter_abbr(stage, iter)}ID" when "draft-wip" then "#{iter_abbr(stage, iter)}WD" when "draft-prelim" then "#{iter_abbr(stage, iter)}PreD" when "draft-public" then "#{iter_abbr(stage, iter)}PD" when "draft-approval" then "#{iter_abbr(stage, iter)}AD" else nil end end |
#status_print(status) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/isodoc/nist/metadata_id.rb', line 59 def status_print(status) case status when "draft-internal" then "Internal Draft" when "draft-wip" then "Work-in-Progress Draft" when "draft-prelim" then "Preliminary Draft" when "draft-public" then "Public Draft" when "draft-approval" then "Approval Draft" when "final" then "Final" when "final-review" then "Under Review" when "final-withdrawn" then "Withdrawn" else super end end |
#stripdate(id) ⇒ Object
86 87 88 89 |
# File 'lib/isodoc/nist/metadata_id.rb', line 86 def stripdate(id) return if id.nil? id.sub(/ \((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[^)]+\)$/, "") end |
#subtitle(ixml, _out) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/isodoc/nist/metadata.rb', line 27 def subtitle(ixml, _out) main = ixml&.at(ns("//bibdata/title[@type = 'subtitle']"))&.text set(:docsubtitle, main) if main short = ixml&.at(ns("//bibdata/title[@type = 'short-subtitle']"))&.text set(:docsubtitle_short, short || main) if short || main main = ixml&.at(ns("//bibdata/title[@type = 'document-class']"))&.text set(:docclasstitle, main) if main end |
#superseding_dates(newdoc) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/isodoc/nist/metadata.rb', line 220 def superseding_dates(newdoc) if cdate = newdoc.at(ns("./date[@type = 'circulated']/on"))&.text set(:superseding_circulated_date, cdate) set(:superseding_circulated_date_monthyear, monthyr(cdate)) end if cdate = newdoc.at(ns("./date[@type = 'issued']/on"))&.text set(:superseding_issued_date, cdate) set(:superseding_issued_date_monthyear, monthyr(cdate)) end if cdate = newdoc.at(ns("./date[@type = 'updated']/on"))&.text set(:superseding_updated_date, cdate) set(:superseding_updated_date_monthyear, monthyr(cdate)) set(:superseding_updated_date_MMMddyyyy, MMMddyyyy(cdate)) end end |
#superseding_doc(ixml) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/isodoc/nist/metadata.rb', line 166 def superseding_doc(ixml) d = ixml.at(ns("//bibdata/relation[@type = 'obsoletedBy']/bibitem")) return unless d set(:superseding_status, status_print(d.at(ns("./status/stage"))&.text || "final")) superseding_iteration(d) docid = d.at(ns("./docidentifier[@type = 'NIST']"))&.text and set(:superseding_docidentifier, docid) docid_long = d.at(ns("./docidentifier[@type = 'nist-long']"))&.text and set(:superseding_docidentifier_long, docid_long) superseding_dates(d) doi = d.at(ns("./uri[@type = 'doi']"))&.text and set(:superseding_doi, doi) uri = d.at(ns("./uri[@type = 'uri']"))&.text and set(:superseding_uri, uri) superseding_titles(ixml, d) = d.xpath(ns("./contributor[role/@type = 'author']/person")) .empty? and = ixml.xpath(ns("//bibdata/contributor[role/@type = 'author']/person")) set(:superseding_authors, extract_person_names()) end |
#superseding_iteration(newdoc) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/isodoc/nist/metadata.rb', line 202 def superseding_iteration(newdoc) return unless newdoc.at(ns("./status/stage"))&.text == "draft-public" iter = newdoc.at(ns("./status/iteration"))&.text || "1" case iter.downcase when "1" set(:superseding_iteration_ordinal, "Initial") set(:superseding_iteration_code, "IPD") when "final" set(:superseding_iteration_ordinal, "Final") set(:superseding_iteration_code, "FPD") else set(:superseding_iteration_ordinal, iter.to_i.localize.to_rbnf_s("SpelloutRules", "spellout-ordinal")) set(:superseding_iteration_code, "#{iter}PD") end end |
#superseding_titles(ixml, newdoc) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/isodoc/nist/metadata.rb', line 188 def superseding_titles(ixml, newdoc) if newdoc.at(ns("./title[@type = 'main']"))&.text set(:superseding_title, newdoc.at(ns("./title[@type = 'main']"))&.text) set(:superseding_subtitle, newdoc.at(ns("./title[@type = 'subtitle']"))&.text) else set(:superseding_title, ixml.at(ns("//bibdata/title[@type = 'main']"))&.text) set(:superseding_subtitle, ixml.at(ns("//bibdata/title[@type = 'subtitle']"))&.text) end end |
#title(ixml, _out) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/isodoc/nist/metadata.rb', line 20 def title(ixml, _out) main = ixml&.at(ns("//bibdata/title[@type = 'main']"))&.text set(:doctitle, main) short = ixml&.at(ns("//bibdata/title[@type = 'short-title']"))&.text set(:doctitle_short, short || main) end |
#unpublished(status) ⇒ Object
55 56 57 |
# File 'lib/isodoc/nist/metadata_id.rb', line 55 def unpublished(status) !/^draft/.match(status).nil? end |
#url(xml, _out) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/isodoc/nist/metadata.rb', line 135 def url(xml, _out) super a = xml.at(ns("//bibdata/uri[@type = 'email']")) and set(:email, a.text) a = xml.at(ns("//bibdata/uri[@type = 'doi']")) and set(:doi, a.text) a = xml.at(ns("//bibdata/uri[@type = 'uri' or not(@type)]")) and set(:url, a.text) end |
#version(ixml, _out) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/isodoc/nist/metadata.rb', line 45 def version(ixml, _out) super rev = ixml&.at(ns("//bibdata/edition"))&.text&.sub(/^Revision /, "") set(:revision, rev) if rev revdate = get[:revdate] set(:revdate_monthyear, monthyr(revdate)) set(:revdate_MMMddyyyy, MMMddyyyy(revdate)) end |
#withdrawal_pending(ixml) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/isodoc/nist/metadata.rb', line 88 def withdrawal_pending(ixml) d = ixml&.at(ns("//bibdata/date[@type = 'obsoleted']"))&.text&.strip or return d += "-01" if /^\d\d\d\d-\d\d$/.match?(d) date = Date.parse(d) or return set(:withdrawal_pending, true) if date > Date.today end |