Sha256: 539de2d2e47cfead6a8b200204b19aa3947e9ee214867e8198130b0473d797f1

Contents?: true

Size: 1.72 KB

Versions: 15

Compression:

Stored size: 1.72 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

=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?
    return isodate if isodate == "--"
    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
end

Version data entries

15 entries across 13 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-nist-1.1.2/lib/isodoc/nist/render_dates.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-nist-1.1.3/lib/isodoc/nist/render_dates.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/metanorma-nist-1.1.2/lib/isodoc/nist/render_dates.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/metanorma-nist-1.1.3/lib/isodoc/nist/render_dates.rb
metanorma-nist-1.1.3 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.1.2 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.1.1 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.1.0 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.10 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.9 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.8 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.7 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.6 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.5 lib/isodoc/nist/render_dates.rb
metanorma-nist-1.0.4 lib/isodoc/nist/render_dates.rb