Sha256: d5aef40aeca091569561e7b56b263b809dfdf95a2fbfc3ea508485b51b688e59

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

module RelatonIho
  class HashConverter < RelatonBib::HashConverter
    class << self
      # @override RelatonIsoBib::HashConverter.hash_to_bib
      # @param args [Hash]
      # @param nested [TrueClass, FalseClass]
      # @return [Hash]
      def hash_to_bib(args, nested = false)
        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 = array(eg).map do |g|
          EditorialGroup.new(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}"
        subwg = value.select do |k, _|
          %i[committee workgroup commission].include? k
        end
        klass.new value[:abbreviation], value[:name], iho_workgroup(subwg)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
relaton-iho-1.7.0 lib/relaton_iho/hash_converter.rb
relaton-iho-1.6.0 lib/relaton_iho/hash_converter.rb
relaton-iho-1.6.pre1 lib/relaton_iho/hash_converter.rb
relaton-iho-1.5.0 lib/relaton_iho/hash_converter.rb
relaton-iho-1.5.pre lib/relaton_iho/hash_converter.rb