Sha256: 10ff5480f516f9fc4f25ca28cddd0b6ec0a034db62710ddb44fc8818dfdadcc1

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 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])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relaton-iso-1.14.1 lib/relaton_iso/hit.rb
relaton-iso-1.14.0 lib/relaton_iso/hit.rb
relaton-iso-1.13.7 lib/relaton_iso/hit.rb