Class: DNZ::Results

Inherits:
Object
  • Object
show all
Extended by:
Memoizable
Defined in:
lib/dnz/results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Memoizable

memoize, memoized_ivar_for

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

#facetsObject (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_countObject (readonly)

Returns the value of attribute result_count.



19
20
21
# File 'lib/dnz/results.rb', line 19

def result_count
  @result_count
end

#resultsObject (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_requestedObject

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

#pageObject

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

#pagesObject

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_pageObject



58
59
60
# File 'lib/dnz/results.rb', line 58

def per_page
  num_results_requested < 1 ? 1 : num_results_requested
end