class IsoDoc::Metadata
Constants
- DATETYPES
- NOLANG
Attributes
fonts_options[RW]
Public Class Methods
new(lang, script, i18n, fonts_options = {})
click to toggle source
# File lib/isodoc/metadata.rb, line 18 def initialize(lang, script, i18n, fonts_options = {}) @metadata = { lang: lang, script: script } DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = "XXX" } @lang = lang @script = script @c = HTMLEntities.new @i18n = i18n @labels = @i18n.get @fonts_options = fonts_options end
Public Instance Methods
MMMddyyyy(isodate)
click to toggle source
# File lib/isodoc/metadata_date.rb, line 32 def MMMddyyyy(isodate) return nil if isodate.nil? arr = isodate.split("-") date = if arr.size == 1 and (/^\d+$/.match isodate) Date.new(*arr.map(&:to_i)).strftime("%Y") elsif arr.size == 2 Date.new(*arr.map(&:to_i)).strftime("%B %Y") else Date.parse(isodate).strftime("%B %d, %Y") end end
agency(xml)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 75 def agency(xml) agency, publisher = agency1(xml) set(:agency, agency.sub(%r{/$}, "")) set(:publisher, @i18n.multiple_and(publisher, @labels["and"])) agency_addr(xml) end
agency1(xml)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 62 def agency1(xml) agency = "" publisher = [] xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\ "organization")).each do |org| name = org&.at(ns("./name"))&.text agency1 = org&.at(ns("./abbreviation"))&.text || name publisher << name if name agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/" end [agency, publisher] end
agency_addr(xml)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 82 def agency_addr(xml) a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/"\ "organization")) or return { subdivision: "./subdivision", pub_phone: "./phone[not(@type = 'fax')]", pub_fax: "./phone[@type = 'fax']", pub_email: "./email", pub_uri: "./uri" }.each do |k, v| n = a.at(ns(v)) and set(k, n.text) end n = a.at(ns("./address/formattedAddress")) and set(:pub_address, n.children.to_xml) end
bibdate(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata_date.rb, line 44 def bibdate(isoxml, _out) isoxml.xpath(ns('//bibdata/date')).each do |d| set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d)) end end
currlang()
click to toggle source
# File lib/isodoc/metadata.rb, line 43 def currlang "[@language = '#{@lang}']" end
docid(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 83 def docid(isoxml, _out) dn = isoxml.at(ns("//bibdata/docidentifier")) set(:docnumber, dn&.text) end
docnumeric(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 95 def docnumeric(isoxml, _out) dn = isoxml.at(ns("//bibdata/docnumber")) set(:docnumeric, dn&.text) end
docstatus(xml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 54 def docstatus(xml, _out) set(:unpublished, true) return unless s = xml.at(ns("//bibdata/status/stage#{NOLANG}")) s1 = xml.at(ns("//bibdata/status/stage#{currlang}")) || s set(:stage, status_print(s.text)) s1 and set(:stage_display, status_print(s1.text)) (i = xml&.at(ns("//bibdata/status/substage#{NOLANG}"))&.text) and set(:substage, i) (i1 = xml&.at(ns("//bibdata/status/substage#{currlang}"))&.text || i) and set(:substage_display, i1) (i2 = xml&.at(ns("//bibdata/status/iteration"))&.text) and set(:iteration, i2) set(:unpublished, unpublished(s.text)) unpublished(s.text) && set(:stageabbr, stage_abbr(s.text)) end
doctype(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 47 def doctype(isoxml, _out) b = isoxml&.at(ns("//bibdata/ext/doctype#{NOLANG}"))&.text || return set(:doctype, status_print(b)) b1 = isoxml&.at(ns("//bibdata/ext/doctype#{currlang}"))&.text || b set(:doctype_display, status_print(b1)) end
draftinfo(draft, revdate)
click to toggle source
# File lib/isodoc/metadata.rb, line 100 def draftinfo(draft, revdate) return "" unless draft draftinfo = " (#{@labels['draft_label']} #{draft}" draftinfo += ", #{revdate}" if revdate draftinfo += ")" l10n(draftinfo, @lang, @script) end
extract_person_affiliations(authors)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 16 def extract_person_affiliations(authors) authors.reduce([]) do |m, a| name = a&.at(ns("./affiliation/organization/name"))&.text subdivs = a&.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ") name and subdivs and !subdivs.empty? and name = l10n("#{name}, #{subdivs}", @lang, @script) location = a&.at(ns("./affiliation/organization/address/formattedAddress"))&.text m << (if !name.nil? && !location.nil? l10n("#{name}, #{location}", @lang, @script) else (name || location || "") end) m end end
extract_person_names(authors)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 3 def extract_person_names(authors) authors.reduce([]) do |ret, a| if a.at(ns("./name/completename")) ret << a.at(ns("./name/completename")).text else forenames = a.xpath(ns("./name/forename")) fn = forenames.each_with_object([]) { |f, m| m << f.text } surname = a&.at(ns("./name/surname"))&.text ret << "#{fn.join(' ')} #{surname}" end end end
extract_person_names_affiliations(authors)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 32 def extract_person_names_affiliations(authors) names = extract_person_names(authors) affils = extract_person_affiliations(authors) ret = {} affils.each_with_index do |a, i| ret[a] ||= [] ret[a] << names[i] end ret end
get()
click to toggle source
# File lib/isodoc/metadata.rb, line 29 def get @metadata end
iso?(org)
click to toggle source
# File lib/isodoc/metadata_contributor.rb, line 55 def iso?(org) name = org&.at(ns("./name"))&.text abbrev = org&.at(ns("./abbreviation"))&.text (abbrev == "ISO" || name == "International Organization for Standardization") end
keywords(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 156 def keywords(isoxml, _out) ret = [] isoxml.xpath(ns("//bibdata/keyword")).each { |kw| ret << kw.text } set(:keywords, ret) end
l10n(a, b, c)
click to toggle source
# File lib/isodoc/metadata.rb, line 14 def l10n(a, b, c) @i18n.l10n(a, b, c) end
labels()
click to toggle source
# File lib/isodoc/metadata.rb, line 33 def labels @labels end
months()
click to toggle source
# File lib/isodoc/metadata_date.rb, line 8 def months { "01": @labels["month_january"], "02": @labels["month_february"], "03": @labels["month_march"], "04": @labels["month_april"], "05": @labels["month_may"], "06": @labels["month_june"], "07": @labels["month_july"], "08": @labels["month_august"], "09": @labels["month_september"], "10": @labels["month_october"], "11": @labels["month_november"], "12": @labels["month_december"], } end
monthyr(isodate)
click to toggle source
# File lib/isodoc/metadata_date.rb, line 25 def monthyr(isodate) m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate return isodate unless m && m[:yr] && m[:mo] l10n("#{months[m[:mo].to_sym]} #{m[:yr]}", @lang, @script) end
note(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 162 def note(isoxml, _out) ret = [] isoxml.xpath(ns("//bibdata/note[@type = 'title-footnote']")).each do |n| ret << n.text end set(:title_footnote, ret) end
ns(xpath)
click to toggle source
# File lib/isodoc/metadata.rb, line 10 def ns(xpath) Common::ns(xpath) end
otherid(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 88 def otherid(isoxml, _out) dn = isoxml.at(ns('//bibdata/docidentifier[@type = "ISBN"]')) set(:isbn, dn&.text) dn = isoxml.at(ns('//bibdata/docidentifier[@type = "ISBN10"]')) set(:isbn10, dn&.text) end
relations(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 129 def relations(isoxml, _out) relations_obsoletes(isoxml) relations_partof(isoxml) end
relations_obsoletes(isoxml)
click to toggle source
# File lib/isodoc/metadata.rb, line 140 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)
click to toggle source
# File lib/isodoc/metadata.rb, line 134 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
set(key, value)
click to toggle source
# File lib/isodoc/metadata.rb, line 37 def set(key, value) @metadata[key] = value end
stage_abbr(docstatus)
click to toggle source
# File lib/isodoc/metadata.rb, line 71 def stage_abbr(docstatus) status_print(docstatus).split(/ /).map { |s| s[0].upcase }.join("") end
status_print(status)
click to toggle source
# File lib/isodoc/metadata.rb, line 79 def status_print(status) status.split(/[- ]/).map(&:capitalize).join(" ") end
subtitle(_isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 125 def subtitle(_isoxml, _out) nil end
title(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 120 def title(isoxml, _out) main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"))&.text set(:doctitle, main) end
unpublished(status)
click to toggle source
# File lib/isodoc/metadata.rb, line 75 def unpublished(status) !status.casecmp("published").zero? end
url(xml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 148 def url(xml, _out) (a = xml.at(ns("//bibdata/uri[not(@type)]"))) && set(:url, a.text) (a = xml.at(ns("//bibdata/uri[@type = 'html']"))) && set(:html, a.text) (a = xml.at(ns("//bibdata/uri[@type = 'xml']"))) && set(:xml, a.text) (a = xml.at(ns("//bibdata/uri[@type = 'pdf']"))) && set(:pdf, a.text) (a = xml.at(ns("//bibdata/uri[@type = 'doc']"))) && set(:doc, a.text) end
version(isoxml, _out)
click to toggle source
# File lib/isodoc/metadata.rb, line 109 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("//bibdata/version/draft"))&.text) revdate = isoxml&.at(ns("//bibdata/version/revision-date"))&.text set(:revdate, revdate) set(:revdate_monthyear, monthyr(revdate)) set(:draftinfo, draftinfo(get[:draft], get[:revdate])) end