Sha256: 192a1e81b9d1263b8ad59631f4547f13e075c3bd1beeb18967292f69b434693c

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module RelatonIso
  # Hit.
  class Hit < RelatonBib::Hit
    # @return [RelatonIsoBib::IsoBibliographicItem]
    attr_writer :fetch, :pubid

    # Update edition for pubid when provided in Bibliographic Item
    def update_edition(bibliographic_item)
      if bibliographic_item.edition
        # add edition to base document if available
        if pubid.base
          pubid.base.edition = bibliographic_item.edition.content
        else
          pubid.edition = bibliographic_item.edition.content
        end
      end
    end

    # Parse page.
    # @param lang [String, nil]
    # @return [RelatonIso::IsoBibliographicItem]
    def fetch(lang = nil)
      @fetch ||= Scrapper.parse_page self, lang
      # update edition for pubid using fetched data
      update_edition(@fetch)
      @fetch
    end

    # @return [Integer]
    def sort_weight
      case hit[:status] # && hit["publicationStatus"]["key"]
      when "Published" then 0
      when "Under development" then 1
      when "Withdrawn" then 2
      when "Deleted" then 3
      else 4
      end
    end

    # @return [Pubid::Iso::Identifier]
    def pubid
      @pubid ||= Pubid::Iso::Identifier.parse_from_title(hit[:title])
    rescue Pubid::Iso::Errors::WrongTypeError => e
      warn "[relaton-iso] unable to find an identifier in \"#{hit[:title]}\"."
      warn "[relaton-iso] #{e.message}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
relaton-iso-1.15.4 lib/relaton_iso/hit.rb
relaton-iso-1.15.3 lib/relaton_iso/hit.rb
relaton-iso-1.15.1 lib/relaton_iso/hit.rb
relaton-iso-1.15.0 lib/relaton_iso/hit.rb
relaton-iso-1.14.3 lib/relaton_iso/hit.rb
relaton-iso-1.14.2 lib/relaton_iso/hit.rb