Sha256: 6a3a9cc07cb761cd2fc57f70ac69910221591eef60f5f75d10a3d336f974483e

Contents?: true

Size: 1.86 KB

Versions: 27

Compression:

Stored size: 1.86 KB

Contents

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

module IsoDoc
  module MPFA
    class Metadata < IsoDoc::Metadata
      def initialize(lang, script, labels)
        super
        here = File.dirname(__FILE__)
        set(:logo, File.expand_path(File.join(here, "html",
                                              "mpfa-logo-no-text@4x.png")))
      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/ext/doctype"))&.text or return

        t = b.split(/[- ]/)
          .map { |w| w.capitalize unless w == "MPF" }.join(" ")
        set(:doctype, t)
      end

      def stage_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
        edition = isoxml.at(ns("//bibdata/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 StandardError
        # invalid dates get thrown
        isodate
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
metanorma-mpfa-0.9.2 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.9.1 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.9.0 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.8 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.7 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.6 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.5 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.4 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.3 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.2 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.1 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.8.0 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.5 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.4 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.3 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.2 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.1 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.7.0 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.6.13 lib/isodoc/mpfa/metadata.rb
metanorma-mpfa-0.6.12 lib/isodoc/mpfa/metadata.rb