Class: Pandoru::Models::SearchResult
Instance Attribute Summary
Attributes inherited from Base
#data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Collection
#<<, #[], #each, #empty?, #first, #initialize, #last, #length, #to_a
Methods inherited from Base
date_field, field, fields, from_json_list, #initialize, #inspect, #populate_from_json, #to_h
Class Method Details
.from_json(api_client, data) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/pandoru/models/search.rb', line 34
def self.from_json(api_client, data)
instance = new(data, api_client)
instance.populate_from_json(data)
if data['songs']
SearchResultItem.from_json_list(api_client, data['songs']).each do |item|
instance << item
end
end
if data['artists']
data['artists'].each do |artist_data|
item_data = {
'artistName' => artist_data['artistName'],
'musicToken' => artist_data['musicToken'],
'score' => artist_data['score'],
'likelyMatch' => artist_data['likelyMatch']
}
item = SearchResultItem.from_json(api_client, item_data)
instance << item
end
end
instance
end
|
Instance Method Details
#artists ⇒ Object
66
67
68
|
# File 'lib/pandoru/models/search.rb', line 66
def artists
select(&:artist?)
end
|
#best_match ⇒ Object
70
71
72
|
# File 'lib/pandoru/models/search.rb', line 70
def best_match
max_by(&:score)
end
|
#songs ⇒ Object
62
63
64
|
# File 'lib/pandoru/models/search.rb', line 62
def songs
select(&:song?)
end
|