Sha256: ce080b1f81696288cf6d6a6563d6131dabd4beffe6d621b172df72d2a7f91b98

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Iecbib
  # Hit.
  class Hit
    # @return [Isobib::HitCollection]
    attr_reader :hit_collection

    # @return [Array<Hash>]
    attr_reader :hit

    # @param hit [Hash]
    # @param hit_collection [Isobib:HitCollection]
    def initialize(hit, hit_collection = nil)
      @hit            = hit
      @hit_collection = hit_collection
    end

    # Parse page.
    # @return [Isobib::IsoBibliographicItem]
    def fetch
      @fetch ||= Scrapper.parse_page @hit
    end

    # @return [String]
    def to_s
      inspect
    end

    # @return [String]
    def inspect
      "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
      "@text=\"#{@hit_collection&.text}\" "\
      "@fetched=\"#{!@fetch.nil?}\" "\
      "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
      "@title=\"#{@hit[:code]}\">"
    end

    # @return [String]
    def to_xml(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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iecbib-0.2.2 lib/iecbib/hit.rb
iecbib-0.2.1 lib/iecbib/hit.rb
iecbib-0.2.0 lib/iecbib/hit.rb
iecbib-0.1.2 lib/iecbib/hit.rb
iecbib-0.1.1 lib/iecbib/hit.rb