Class: DNZ::Results
- Inherits:
-
Object
- Object
- DNZ::Results
- Extended by:
- Memoizable
- Defined in:
- lib/dnz/results.rb
Instance Attribute Summary collapse
-
#facets ⇒ Object
readonly
An array of facets.
-
#result_count ⇒ Object
readonly
Returns the value of attribute result_count.
-
#results ⇒ Object
readonly
An array of results.
Instance Method Summary collapse
-
#initialize(xml, search) ⇒ Results
constructor
A new instance of Results.
-
#num_results_requested ⇒ Object
The number of results requested via the :num_results option (see
Client.search
). -
#page ⇒ Object
The current page of results, based on the number of requested results and the start value (see
Client.search
). -
#pages ⇒ Object
The number of pages available for the current search.
- #per_page ⇒ Object
Methods included from Memoizable
Constructor Details
#initialize(xml, search) ⇒ Results
Returns a new instance of Results.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dnz/results.rb', line 34 def initialize(xml, search) reset @xml = xml @search = search # Parse the results parse_attributes parse_facets parse_results paginate_results if defined? WillPaginate::Collection end |
Instance Attribute Details
#facets ⇒ Object (readonly)
An array of facets.
Example
search = client.search('text', :facets => 'category')
categories = search.facets['category']
categories.each do |category|
puts '%d results in category %s' % [category.count, category.name]
end
29 30 31 |
# File 'lib/dnz/results.rb', line 29 def facets @facets end |
#result_count ⇒ Object (readonly)
Returns the value of attribute result_count.
19 20 21 |
# File 'lib/dnz/results.rb', line 19 def result_count @result_count end |
#results ⇒ Object (readonly)
An array of results. If the mislav-will_paginate gem is installed this will return a paginated array.
32 33 34 |
# File 'lib/dnz/results.rb', line 32 def results @results end |
Instance Method Details
#num_results_requested ⇒ Object
The number of results requested via the :num_results option (see Client.search
).
63 64 65 |
# File 'lib/dnz/results.rb', line 63 def num_results_requested @num_results_requested || 20 end |
#page ⇒ Object
The current page of results, based on the number of requested results and the start value (see Client.search
).
49 50 51 |
# File 'lib/dnz/results.rb', line 49 def page (((@start || 0) / num_results_requested) + 1) rescue 1 end |
#pages ⇒ Object
The number of pages available for the current search.
54 55 56 |
# File 'lib/dnz/results.rb', line 54 def pages num_results_requested < result_count ? (result_count.to_f / num_results_requested).ceil : 1 end |
#per_page ⇒ Object
58 59 60 |
# File 'lib/dnz/results.rb', line 58 def per_page num_results_requested < 1 ? 1 : num_results_requested end |