Class: RatingsAggregator::Base
- Inherits:
-
Object
- Object
- RatingsAggregator::Base
- Defined in:
- lib/ratings_aggregator/base.rb
Instance Method Summary collapse
Instance Method Details
#api ⇒ Object
27 28 29 |
# File 'lib/ratings_aggregator/base.rb', line 27 def api @api ||= RatingsAggregator::Api.new end |
#search(search_title) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ratings_aggregator/base.rb', line 7 def search(search_title) response = api.call(t: search_title, apikey: @key) # puts response if response[:data]["Response"] == "False" nil else # pulls out the strings that represent the rating scores = response[:data]["Ratings"].map {|x| x["Value"]} sum = 0.0 .each do |score| to_add = score.to_f if /.+\/10$/.match score to_add *= 10 end sum += to_add end aggregate_score = (sum/.length).round end end |
#set_key(key) ⇒ Object
31 32 33 |
# File 'lib/ratings_aggregator/base.rb', line 31 def set_key(key) @key = key end |