Sha256: 588fe290ad1d7ca346c2040fa1e9019f38e4b8fae96187afd3aad6db44b2a0b7

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

# frozen_string_literal: true

module RelatonIso
  # Hit.
  class Hit < RelatonBib::Hit
    # @return [RelatonIso::HitCollection]
    attr_reader :hit_collection

    # Parse page.
    # @param lang [String, NilClass]
    # @return [RelatonIso::IsoBibliographicItem]
    def fetch(lang = nil)
      @fetch ||= Scrapper.parse_page @hit, lang
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder = nil, **opts)
      if builder
        fetch.to_xml builder, **opts
      else
        builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
          fetch.to_xml xml, **opts
        end
        builder.doc.root.to_xml
      end
    end

    def sort_weight
      case hit["publicationStatus"]
      when "Published" then 0
      when "Under development" then 1
      when "Withdrawn" then 2
      else
        3
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relaton-iso-0.10.0 lib/relaton_iso/hit.rb
relaton-iso-0.9.0 lib/relaton_iso/hit.rb
relaton-iso-0.8.2 lib/relaton_iso/hit.rb
relaton-iso-0.8.1 lib/relaton_iso/hit.rb