Class: Isobib::HitPages
- Inherits:
-
Array
- Object
- Array
- Isobib::HitPages
- Defined in:
- lib/isobib/hit_pages.rb
Overview
Pages of hits.
Instance Attribute Summary collapse
- #text ⇒ String readonly
Instance Method Summary collapse
- #[](idx) ⇒ Isobib::HitCollection
- #each(&block) ⇒ Object
-
#initialize(text) ⇒ HitPages
constructor
A new instance of HitPages.
- #inspect ⇒ Object
- #last ⇒ Isobib::HitCollection
- #map(&block) ⇒ Array
- #size ⇒ Integer
- #to_s ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(text) ⇒ HitPages
Returns a new instance of HitPages.
16 17 18 19 20 21 22 |
# File 'lib/isobib/hit_pages.rb', line 16 def initialize(text) @text = text @index = Algolia::Index.new 'all_en' resp = @index.search(text, facetFilters: ['category:standard']) @nb_pages = resp['nbPages'] self << HitCollection.new(resp['hits'], self) end |
Instance Attribute Details
#text ⇒ String (readonly)
13 14 15 |
# File 'lib/isobib/hit_pages.rb', line 13 def text @text end |
Instance Method Details
#[](idx) ⇒ Isobib::HitCollection
31 32 33 34 35 36 |
# File 'lib/isobib/hit_pages.rb', line 31 def [](idx) # collection i return if idx + 1 > @nb_pages collection idx super end |
#each(&block) ⇒ Object
47 48 49 50 51 |
# File 'lib/isobib/hit_pages.rb', line 47 def each(&block) @nb_pages.times do |n| yield self[n] if block end end |
#inspect ⇒ Object
57 58 59 60 |
# File 'lib/isobib/hit_pages.rb', line 57 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @text=#{@text} "\ "@pages=#{@nb_pages}>" end |
#last ⇒ Isobib::HitCollection
25 26 27 |
# File 'lib/isobib/hit_pages.rb', line 25 def last collection(@nb_pages - 1) end |
#map(&block) ⇒ Array
39 40 41 42 43 44 45 |
# File 'lib/isobib/hit_pages.rb', line 39 def map(&block) m = [] @nb_pages.times do |n| m << yield(self[n]) if block end m end |
#size ⇒ Integer
63 64 65 |
# File 'lib/isobib/hit_pages.rb', line 63 def size @nb_pages end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/isobib/hit_pages.rb', line 53 def to_s inspect end |
#to_xml ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isobib/hit_pages.rb', line 67 def to_xml builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.documents do each do |page| page.fetch page.each { |hit| hit.to_xml xml } end end end builder.to_xml end |