Class: Popularity::MultiSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/popularity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @searches = options[: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

#searchesObject

Returns the value of attribute searches.



35
36
37
# File 'lib/popularity.rb', line 35

def searches
  @searches
end

#sourcesObject

Returns the value of attribute sources.



36
37
38
# File 'lib/popularity.rb', line 36

def sources
  @sources
end

Instance Method Details

#resultsObject



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(options = {})      
  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

#totalObject



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