Class: Popularity::MultiSearch
- Inherits:
-
Object
- Object
- Popularity::MultiSearch
- Defined in:
- lib/popularity.rb
Instance Attribute Summary collapse
-
#searches ⇒ Object
Returns the value of attribute searches.
-
#sources ⇒ Object
Returns the value of attribute sources.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MultiSearch
constructor
A new instance of MultiSearch.
- #results ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MultiSearch
Returns a new instance of MultiSearch.
36 37 38 39 40 41 42 43 44 |
# File 'lib/popularity.rb', line 36 def initialize( = {}) @searches = [:urls].collect { |url| Search.new(url) } @searches.each do |search| search.results.each do |result| add_search_result(result) end end end |
Instance Attribute Details
#searches ⇒ Object
Returns the value of attribute searches.
33 34 35 |
# File 'lib/popularity.rb', line 33 def searches @searches end |
#sources ⇒ Object
Returns the value of attribute sources.
34 35 36 |
# File 'lib/popularity.rb', line 34 def sources @sources end |
Instance Method Details
#as_json(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/popularity.rb', line 50 def as_json( = {}) json = {} self.searches.collect do |search| json[search.url] = search.as_json end self.sources.collect do |source| json[source.to_s] = self.send(source.to_sym).as_json end json["total"] = total json end |
#results ⇒ Object
46 47 48 |
# File 'lib/popularity.rb', line 46 def results searches.collect(&:results).reduce(:+) end |
#total ⇒ Object
65 66 67 |
# File 'lib/popularity.rb', line 65 def total self.searches.collect(&:total).compact.reduce(:+) end |