Class: RelatonBib::HitCollection
- Extended by:
- Forwardable
- Defined in:
- lib/relaton_bib/hit_collection.rb
Instance Attribute Summary collapse
- #fetched ⇒ TrueClass, FalseClass readonly
- #text ⇒ String readonly
- #year ⇒ String readonly
Instance Method Summary collapse
- #fetch ⇒ RelatonIso::HitCollection
-
#initialize(text, year = nil) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #inspect ⇒ String
- #reduce!(sum, &block) ⇒ Object
- #select(&block) ⇒ Object
- #to_s ⇒ Object
-
#to_xml(**opts) ⇒ String
XML.
Constructor Details
#initialize(text, year = nil) ⇒ HitCollection
Returns a new instance of HitCollection.
20 21 22 23 24 25 |
# File 'lib/relaton_bib/hit_collection.rb', line 20 def initialize(text, year = nil) @array = [] @text = text @year = year @fetched = false end |
Instance Attribute Details
#fetched ⇒ TrueClass, FalseClass (readonly)
11 12 13 |
# File 'lib/relaton_bib/hit_collection.rb', line 11 def fetched @fetched end |
#text ⇒ String (readonly)
14 15 16 |
# File 'lib/relaton_bib/hit_collection.rb', line 14 def text @text end |
#year ⇒ String (readonly)
17 18 19 |
# File 'lib/relaton_bib/hit_collection.rb', line 17 def year @year end |
Instance Method Details
#fetch ⇒ RelatonIso::HitCollection
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/relaton_bib/hit_collection.rb', line 28 def fetch workers = WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end |
#inspect ⇒ String
75 76 77 |
# File 'lib/relaton_bib/hit_collection.rb', line 75 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @ref=#{@text} @fetched=#{@fetched}>" end |
#reduce!(sum, &block) ⇒ Object
65 66 67 68 |
# File 'lib/relaton_bib/hit_collection.rb', line 65 def reduce!(sum, &block) @array = @array.reduce sum, &block self end |
#select(&block) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/relaton_bib/hit_collection.rb', line 57 def select(&block) me = deep_dup array_dup = instance_variable_get(:@array).deep_dup me.instance_variable_set(:@array, array_dup) array_dup.select!(&block) me end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/relaton_bib/hit_collection.rb', line 70 def to_s inspect end |
#to_xml(**opts) ⇒ String
Returns XML.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relaton_bib/hit_collection.rb', line 45 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 **opts.merge(builder: xml) end end end builder.to_xml end |