Class: Median::Primo::SearchResult
- Inherits:
-
Object
- Object
- Median::Primo::SearchResult
- Includes:
- XmlSupport
- Defined in:
- lib/median/primo/search_result.rb
Instance Attribute Summary collapse
-
#facets ⇒ Object
Returns the value of attribute facets.
-
#records ⇒ Object
Returns the value of attribute records.
-
#search_request ⇒ Object
Returns the value of attribute search_request.
Instance Method Summary collapse
- #has_next_page? ⇒ Boolean
- #has_previous_page? ⇒ Boolean
-
#initialize(xml, search_request) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #next_page ⇒ Object
- #number_of_pages ⇒ Object
- #previous_page ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(xml, search_request) ⇒ SearchResult
Returns a new instance of SearchResult.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/median/primo/search_result.rb', line 8 def initialize(xml, search_request) raise "XML result required. Given parameter was nil." unless xml.present? raise "Request required. Given parameter was nil." unless search_request.present? xml = Nokogiri::XML(xml) if xml.is_a?(String) xml.remove_namespaces! super(xml) @xml = xml @records = xml.xpath("//DOCSET/DOC").collect { |xml| Median::Primo::Record.new(xml) } @facets = xml.xpath("//FACETLIST//FACET").collect { |xml| Median::Primo::Facet.new(xml) } @search_request = search_request end |
Instance Attribute Details
#facets ⇒ Object
Returns the value of attribute facets.
22 23 24 |
# File 'lib/median/primo/search_result.rb', line 22 def facets @facets end |
#records ⇒ Object
Returns the value of attribute records.
22 23 24 |
# File 'lib/median/primo/search_result.rb', line 22 def records @records end |
#search_request ⇒ Object
Returns the value of attribute search_request.
22 23 24 |
# File 'lib/median/primo/search_result.rb', line 22 def search_request @search_request end |
Instance Method Details
#has_next_page? ⇒ Boolean
32 33 34 |
# File 'lib/median/primo/search_result.rb', line 32 def has_next_page? search_request.page < number_of_pages end |
#has_previous_page? ⇒ Boolean
36 37 38 |
# File 'lib/median/primo/search_result.rb', line 36 def has_previous_page? search_request.page > 1 end |
#next_page ⇒ Object
40 41 42 |
# File 'lib/median/primo/search_result.rb', line 40 def next_page has_next_page? ? search_request.page + 1 : number_of_pages end |
#number_of_pages ⇒ Object
28 29 30 |
# File 'lib/median/primo/search_result.rb', line 28 def number_of_pages (total_hits / search_request.page_size) + 1 end |
#previous_page ⇒ Object
44 45 46 |
# File 'lib/median/primo/search_result.rb', line 44 def previous_page has_previous_page? ? search_request.page - 1 : 1 end |
#to_xml ⇒ Object
24 25 26 |
# File 'lib/median/primo/search_result.rb', line 24 def to_xml @xml end |