Sha256: d6dedd2ae0071a46093ac6272afe3fd5017811427a7abd53a930ef623ddee1b1

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

module RelatonIho
  module HashConverter
    include RelatonBib::HashConverter
    extend self
    # @override RelatonIsoBib::HashConverter.hash_to_bib
    # @param args [Hash]
    # @param nested [TrueClass, FalseClass]
    # @return [Hash]
    def hash_to_bib(args)
      ret = super
      return if ret.nil?

      commentperiod_hash_to_bib ret
      ret
    end

    private

    # @param item_hash [Hash]
    # @return [RelatonBib::BibliographicItem]
    def bib_item(**item_hash)
      IhoBibliographicItem.new(**item_hash)
    end

    # @param ret [Hash]
    def commentperiod_hash_to_bib(ret)
      ret[:commentperiod] &&= CommentPeriond.new(**ret[:commentperiod])
    end

    # @param ret [Hash]
    def editorialgroup_hash_to_bib(ret)
      eg = ret[:editorialgroup]
      return unless eg.is_a?(Hash) || eg&.any?

      collection = RelatonBib.array(eg).map do |g|
        EditorialGroup.new(RelatonBib.array(g).map { |wg| iho_workgroup wg })
      end
      ret[:editorialgroup] = EditorialGroupCollection.new collection
    end

    # @param ihowg [Hash]
    # @return [RelatonIho::Committee, RelatonIho::Workgroup,
    #          RelatonIho::Commission]
    def iho_workgroup(ihowg)
      key, value = ihowg&.first
      return unless key && value.is_a?(Hash)

      klass = Object.const_get "RelatonIho::#{key.capitalize}"
      wgs = %i[committee workgroup commission]
      subwg = value.select { |k, _| wgs.include? k }
      klass.new value[:abbreviation], value[:name], iho_workgroup(subwg)
    end

    def create_doctype(**args)
      DocumentType.new(**args)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relaton-iho-1.19.1 lib/relaton_iho/hash_converter.rb
relaton-iho-1.19.0 lib/relaton_iho/hash_converter.rb
relaton-iho-1.18.0 lib/relaton_iho/hash_converter.rb
relaton-iho-1.17.0 lib/relaton_iho/hash_converter.rb