7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ratings_aggregator/base.rb', line 7
def search(search_title)
begin
response = api.call(t: search_title, apikey: @key)
rescue Exception => e
puts "Please set the API key"
return
end
if response[:data]["Response"] == "False"
nil
else
rating_scores = response[:data]["Ratings"].map {|x| x["Value"]}
sum = 0.0
rating_scores.each do |score|
to_add = score.to_f
if /.+\/10$/.match score
to_add *= 10
end
sum += to_add
end
aggregate_score = (sum/rating_scores.length).round
end
end
|