Class: RelatonBib::HitCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, year = nil) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • text (String)

    reference to search



19
20
21
22
23
24
# File 'lib/relaton_bib/hit_collection.rb', line 19

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

Instance Attribute Details

#fetchedTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


10
11
12
# File 'lib/relaton_bib/hit_collection.rb', line 10

def fetched
  @fetched
end

#textString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/relaton_bib/hit_collection.rb', line 13

def text
  @text
end

#yearString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/relaton_bib/hit_collection.rb', line 16

def year
  @year
end

Instance Method Details

#fetchRelatonIso::HitCollection

Returns:

  • (RelatonIso::HitCollection)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/relaton_bib/hit_collection.rb', line 27

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

#inspectString

Returns:

  • (String)


69
70
71
# File 'lib/relaton_bib/hit_collection.rb', line 69

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

#reduce!(sum, &block) ⇒ Object



59
60
61
62
# File 'lib/relaton_bib/hit_collection.rb', line 59

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

#select(&block) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/relaton_bib/hit_collection.rb', line 51

def select(&block)
  me = self.deep_dup
  array_dup = self.instance_variable_get(:@array).deep_dup
  me.instance_variable_set(:@array, array_dup)
  array_dup.select!(&block)
  me
end

#to_sObject



64
65
66
# File 'lib/relaton_bib/hit_collection.rb', line 64

def to_s
  inspect
end

#to_xml(**opts) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/relaton_bib/hit_collection.rb', line 39

def to_xml(**opts)
  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
    xml.documents do
      @array.each do |hit|
        hit.fetch
        hit.to_xml xml, **opts
      end
    end
  end
  builder.to_xml
end