Class: Relaton::Core::HitCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/relaton/core/hit_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, year = nil) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • reference to search

  • (defaults to: nil)

    year of publication



24
25
26
27
28
29
# File 'lib/relaton/core/hit_collection.rb', line 24

def initialize(ref, year = nil)
  @array = []
  @ref = ref
  @year = year
  @fetched = false
end

Instance Attribute Details

#fetchedTrueClass, FalseClass (readonly)

Returns:



12
13
14
# File 'lib/relaton/core/hit_collection.rb', line 12

def fetched
  @fetched
end

#refString (readonly)

Returns:



15
16
17
# File 'lib/relaton/core/hit_collection.rb', line 15

def ref
  @ref
end

#yearString (readonly)

Returns:



18
19
20
# File 'lib/relaton/core/hit_collection.rb', line 18

def year
  @year
end

Instance Method Details

#fetchself

Fetches hits from the data source

Returns:

  • self object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/relaton/core/hit_collection.rb', line 36

def fetch
  workers = WorkersPool.new 4
  workers.worker(&:item)
  each do |hit|
    workers << hit
  end
  workers.end
  workers.result
  @fetched = true
  self
end

#inspectString

Returns String representation of the collection

Returns:

  • String representation of the collection



101
102
103
# File 'lib/relaton/core/hit_collection.rb', line 101

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

#reduce!(sum, &block) ⇒ Object



82
83
84
85
# File 'lib/relaton/core/hit_collection.rb', line 82

def reduce!(sum, &block)
  @array = @array.reduce sum, &block
  self
end

#select!(&block) ⇒ RelatonBib::HitCollection

Selects matching hits and returns a new collection

Parameters:

  • proc to select hits

Returns:

  • new hit collection



77
78
79
80
# File 'lib/relaton/core/hit_collection.rb', line 77

def select!(&block)
  @array.select!(&block)
  self
end

#to_sString

Returns String representation of the collection

Returns:

  • String representation of the collection



92
93
94
# File 'lib/relaton/core/hit_collection.rb', line 92

def to_s
  inspect
end