Sha256: f0f47ece13c96aef5bca287d87284e7ba7dd2a34867b20ea6b4e59125224f614

Contents?: true

Size: 1.25 KB

Versions: 20

Compression:

Stored size: 1.25 KB

Contents

module RelatonIsoBib
  # Iso ICS classificator.
  class Ics < Isoics::ICS
    # @param code [String, NilClass]
    # @param field [Integer, NilClass]
    # @param group [Integer, NilClass]
    # @param subgroup [Integer, NilClass]
    def initialize(code = nil, field: nil, group: nil, subgroup: nil)
      unless code || field
        raise ArgumentError,
              "wrong arguments (should be string or { fieldcode: [String] }"
      end

      field, group, subgroup = code.split "." if code
      super fieldcode: field, groupcode: group, subgroupcode: subgroup
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.ics do
        builder.code code
        builder.text_ description
      end
    end

    # @return [Hash]
    def to_hash
      hash = {}
      hash["code"] = code if code
      hash["text"] = description if description
      hash
    end

    # @param prefix [String]
    # @param count [Integer] number of ICS
    # @return [String]
    def to_asciibib(prefix = "", count = 1)
      pref = prefix.empty? ? prefix : prefix + "."
      pref += "ics"
      out = count > 1 ? "#{pref}::\n" : ""
      out += "#{pref}.code:: #{code}\n"
      out += "#{pref}.description:: #{description}\n"
      out
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
relaton-iso-bib-1.20.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.19.2 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.19.1 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.19.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.18.2 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.18.1 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.18.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.17.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.16.2 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.16.1 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.16.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.14.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.13.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.12.1 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.12.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.11.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.10.1 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.10.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.9.0 lib/relaton_iso_bib/ics.rb
relaton-iso-bib-1.8.1 lib/relaton_iso_bib/ics.rb