Sha256: a8016ed2c77531d0afcf00c3bd4c745e4e419d349bdd90c7dad86db5200a6968

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module Iso690Render
  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)}–#{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.MMMddyyyy(isodate)
    return nil if isodate.nil?
    return isodate if isodate == "--"
    arr = isodate.split("-")
    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
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
metanorma-nist-1.3.2 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.3.1 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.3.0 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.16 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.15 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.14 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.13 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.12 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.11 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.2.10 lib/isodoc/nist/render_dates.rb