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
-
#initialize(options = {}) ⇒ MultiSearch
constructor
A new instance of MultiSearch.
- #results ⇒ Object
- #to_json(options = {}) ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MultiSearch
Returns a new instance of MultiSearch.
38 39 40 41 42 43 44 45 46 |
# File 'lib/popularity.rb', line 38 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.
35 36 37 |
# File 'lib/popularity.rb', line 35 def searches @searches end |
#sources ⇒ Object
Returns the value of attribute sources.
36 37 38 |
# File 'lib/popularity.rb', line 36 def sources @sources end |
Instance Method Details
#results ⇒ Object
48 49 50 |
# File 'lib/popularity.rb', line 48 def results searches.collect(&:results).reduce(:+) end |
#to_json(options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/popularity.rb', line 52 def to_json( = {}) json = {} self.searches.collect do |search| json[search.url] = search.to_json end self.sources.collect do |source| json[source.to_s] = self.send(source.to_sym).to_json end json["total"] = total json end |
#total ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/popularity.rb', line 67 def total total = 0 self.searches.each do |a| total += a.total end total end |