lib/isodoc/nist/render.rb in metanorma-nist-0.2.14 vs lib/isodoc/nist/render.rb in metanorma-nist-1.0.0

- old
+ new

@@ -1,7 +1,9 @@ require "nokogiri" require "twitter_cldr" +require_relative "render_contributors" +require_relative "render_dates" module Iso690Render =begin Out of scope: Provenance (differentiating elements by @source in rendering) =end @@ -10,89 +12,10 @@ docxml = Nokogiri::XML(bib) docxml.remove_namespaces! parse(docxml.root, embedded) end -=begin - def self.multiplenames_and(names) - return "" if names.length == 0 - return names[0] if names.length == 1 - return "#{names[0]} and #{names[1]}" if names.length == 2 - names[0..-2].join(", ") + " and #{names[-1]}" - end -=end - - def self.multiplenames(names) - names.join(", ") - end - - def self.extract_orgname(org) - name = org.at("./name") - name&.text || "--" - end - - def self.frontname(given, initials) - if given.empty? && initials.empty? then "" - elsif initials.empty? - given.map{ |m| m.text[0] }.join("") - else - initials.map{ |m| m.text[0] }.join("") - end - end - - def self.commajoin(a, b) - return a unless b - return b unless a - #"#{a}, #{b}" - "#{a} #{b}" - end - - def self.extract_personname(person) - completename = person.at("./name/completename") - return completename.text if completename - surname = person.at("./name/surname") - initials = person.xpath("./name/initials") - forenames = person.xpath("./name/forename") - #given = [] - #forenames.each { |x| given << x.text } - #given.empty? && initials.each { |x| given << x.text } - commajoin(surname&.text, frontname(forenames, initials)) - end - - def self.extractname(contributor) - org = contributor.at("./organization") - person = contributor.at("./person") - return extract_orgname(org) if org - return extract_personname(person) if person - "--" - end - - def self.contributorRole(contributors) - return "" unless contributors.length > 0 - if contributors[0]&.at("role/@type")&.text == "editor" - return contributors.length > 1 ? " (Eds.)" : "(Ed.)" - end - "" - end - - def self.creatornames(doc) - cr = doc.xpath("./contributor[role/@type = 'author']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'performer']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'adapter']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'translator']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'editor']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'publisher']") - cr.empty? and cr = doc.xpath("./contributor[role/@type = 'distributor']") - cr.empty? and cr = doc.xpath("./contributor") - cr.empty? and return "" - ret = [] - cr.each do |x| - ret << extractname(x) - end - multiplenames(ret) + contributorRole(cr) - end - def self.title(doc) doc&.at("./title")&.text end def self.medium(doc) @@ -129,38 +52,10 @@ ret += ": " if place && publisher ret += publisher if publisher ret end - def self.date1(date) - return nil if date.nil? - on = date&.at("./on")&.text - from = date&.at("./from")&.text - to = date&.at("./to")&.text - return MMMddyyyy(on) if on - return "#{MMMddyyyy(from)}&ndash;#{MMMddyyyy(to)}" if from - nil - end - - def self.date(doc) - updated = date1(doc&.at("./date[@type = 'updated']")) - pub = date1(doc&.at("./date[@type = 'issued']")) - if pub - ret = pub - ret += " (updated #{updated})" if updated - return ret - end - pub = date1(doc&.at("./date[@type = 'circulated']")) and - return pub - date1(doc&.at("./date")) - end - - def self.year(date) - return nil if date.nil? - date.sub(/^(\d\d\d\d).*$/, "\\1") - end - def self.series_title(doc) s = doc.at("./series[@type = 'main']") || doc.at("./series[not(@type)]") || doc.at("./series") s&.at("./title")&.text @@ -256,46 +151,9 @@ localities.each do |l| ret << extent1(l["type"] || "page", l.at("./referenceFrom"), l.at("./referenceTo")) end ret.join(", ") - end - -=begin - def self.monthyr(isodate) - return nil if isodate.nil? - arr = isodate.split("-") - date = if arr.size == 2 - DateTime.new(*arr.map(&:to_i)) - else - DateTime.parse(isodate) - end - date.localize(:en).to_additional_s("yMMMM") - end - - def self.mmddyyyy(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("%m-%Y") - else - Date.parse(isodate).strftime("%m-%d-%Y") - end - end -=end - - def self.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 def self.draft(doc) return nil unless is_nist(doc) dr = doc&.at("./status/stage")&.text