Sha256: 9df5ae155bd76b3a64bb58cd283a9e5dfc7d3e29b89b6a1f9a19f5eb2748e071

Contents?: true

Size: 1.8 KB

Versions: 9

Compression:

Stored size: 1.8 KB

Contents

require "isodoc"
require "twitter_cldr"
require 'date'

module IsoDoc
  module Mpfd

    class Metadata < IsoDoc::Metadata
      def initialize(lang, script, labels)
        super
        # set(:status, "")
      end

      def title(isoxml, _out)
        main = isoxml&.at(ns("//bibdata/title[@language='en']"))&.text
        set(:doctitle, main)
      end

      def subtitle(_isoxml, _out)
        nil
      end

      def author(isoxml, _out)
        publisher = isoxml.at(ns("//bibdata/contributor/organization/name"))
        set(:publisher, publisher.text) if publisher
      end

      def docid(isoxml, _out)
        docnumber = isoxml.at(ns("//bibdata/docidentifier"))
        set(:docnumber, docnumber&.text)
      end

      def doctype(isoxml, _out)
        b = isoxml.at(ns("//bibdata")) || return
        return unless b["type"]
        t = b["type"].split(/[- ]/).
          map{ |w| w.capitalize unless w == "MPF" }.join(" ")
        set(:doctype, t)
      end

      def status_abbr(status)
        case status
        when "working-draft" then "wd"
        when "committee-draft" then "cd"
        when "draft-standard" then "d"
        else
          ""
        end
      end

      def version(isoxml, _out)
        super
        revdate = get[:revdate]
        set(:revdate_monthyear, monthyr(revdate))
        edition = isoxml.at(ns("//version/edition"))
        if edition
          set(
            :edition,
            edition.text.to_i.localize.
              to_rbnf_s("SpelloutRules", "spellout-ordinal").
              split(/(\W)/).map(&:capitalize).join
          )
        end
      end

      def monthyr(isodate)
        date = DateTime.parse(isodate)
        date.strftime('%-d %B %Y')    #=> "Sun 04 Feb 2001"
      rescue
        # invalid dates get thrown
        isodate
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
metanorma-mpfd-0.1.10 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.8 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.7 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.6 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.5 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.4 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.3 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.2 lib/isodoc/mpfd/metadata.rb
metanorma-mpfd-0.1.1 lib/isodoc/mpfd/metadata.rb