class Waistband::SearchResults

Constants

DEFAULT_PAGE_SIZE

Public Class Methods

new(search_hash, options = {}) click to toggle source
# File lib/waistband/search_results.rb, line 23
def initialize(search_hash, options = {})
  @page = (options[:page] || 1).to_i
  @page_size = (options[:page_size] || DEFAULT_PAGE_SIZE).to_i
  @search_hash = search_hash
end

Public Instance Methods

hits() click to toggle source
# File lib/waistband/search_results.rb, line 29
def hits
  raise ::Waistband::Errors::NoSearchHits.new("No search hits!") unless @search_hash['hits']
  @search_hash['hits']['hits']
end
method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/waistband/search_results.rb, line 55
def method_missing(method_name, *args, &block)
  return @search_hash[method_name.to_s] if @search_hash.has_key?(method_name.to_s)
  super
end
paginated_hits() click to toggle source
# File lib/waistband/search_results.rb, line 42
def paginated_hits
  ::Waistband::SearchResults::PaginatedArray.new(hits, current_page: @page, page_size: @page_size, total_count: total_results)
end
paginated_results() click to toggle source
# File lib/waistband/search_results.rb, line 46
def paginated_results
  ::Waistband::SearchResults::PaginatedArray.new(results, current_page: @page, page_size: @page_size, total_count: total_results)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/waistband/search_results.rb, line 60
def respond_to_missing?(method_name, include_private = false)
  return true if @search_hash.has_key?(method_name.to_s)
  super
end
results() click to toggle source
# File lib/waistband/search_results.rb, line 34
def results
  raise ::Waistband::Errors::NoSearchHits.new("No search hits!") unless @search_hash['hits']

  hits.map do |hit|
    ::Waistband::Result.new(hit)
  end
end
total_results() click to toggle source
# File lib/waistband/search_results.rb, line 50
def total_results
  raise ::Waistband::Errors::NoSearchHits.new("No search hits!") unless @search_hash['hits']
  @search_hash['hits']['total']
end