Sha256: a6aacd07c333050ae438d3a7b6d459e56e8684c58053375abccce704af53bcc9

Contents?: true

Size: 863 Bytes

Versions: 3

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

require "relaton_iso/hit"

module RelatonIso
  # Page of hit collection.
  class HitCollection < Array
    # @return [TrueClass, FalseClass]
    attr_reader :fetched

    # @return [RelatonIso::HitPages]
    attr_reader :hit_pages

    # @param hits [Array<Hash>]
    def initialize(hits, hit_pages = nil)
      concat(hits.map { |h| Hit.new(h, self) })
      @fetched = false
      @hit_pages = hit_pages
    end

    # @return [RelatonIso::HitCollection]
    def fetch
      workers = RelatonBib::WorkersPool.new 4
      workers.worker(&:fetch)
      each do |hit|
        workers << hit
      end
      workers.end
      workers.result
      @fetched = true
      self
    end

    def to_s
      inspect
    end

    def inspect
      "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relaton-iso-0.5.2 lib/relaton_iso/hit_collection.rb
relaton-iso-0.5.1 lib/relaton_iso/hit_collection.rb
relaton-iso-0.5.0 lib/relaton_iso/hit_collection.rb