Class: BBC::Redux::SearchResults

Inherits:
Object
  • Object
show all
Defined in:
lib/bbc/redux/search_results.rb

Overview

Search results container

Examples:

Properties of search results


results = redux_client.search(:name => 'Pingu')

results.created_at     #=> DateTime
results.query          #=> Hash
results.query_time     #=> Float
results.assets         #=> Array<BBC::Redux::Asset>
results.total          #=> Integer
results.total_returned #=> Integer
results.has_more?      #=> Boolean

Iterating all search results


results = redux_client.search(:name => 'Pingu', :offset => 0)

while true do
  results.assets.each do |asset|
    puts asset.name
  end

  if results.has_more?
    next_query = results.query.merge({
      :offset => results.query[:offset] + 10
    })

    results = redux_client.search(next_query)
  else
    break
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assetsArray<BBC::Redux::Asset> (readonly)


59
# File 'lib/bbc/redux/search_results.rb', line 59

attribute :assets, Array[Asset]

#created_atDateTime (readonly)


47
# File 'lib/bbc/redux/search_results.rb', line 47

attribute :created_at, DateTime

#offsetInteger (readonly)


63
# File 'lib/bbc/redux/search_results.rb', line 63

attribute :offset, Integer

#queryHash (readonly)


51
# File 'lib/bbc/redux/search_results.rb', line 51

attribute :query, Hash

#query_timeFloat (readonly)


55
# File 'lib/bbc/redux/search_results.rb', line 55

attribute :query_time, Float

#totalInteger (readonly)


67
# File 'lib/bbc/redux/search_results.rb', line 67

attribute :total, Integer

#total_returnedInteger (readonly)


71
# File 'lib/bbc/redux/search_results.rb', line 71

attribute :total_returned, Integer

Instance Method Details

#has_more?Boolean


75
76
77
# File 'lib/bbc/redux/search_results.rb', line 75

def has_more?
  (offset + total_returned) < total
end