Class: Vagalume::SearchResult

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSearchResult

Returns a new instance of SearchResult.



5
6
7
# File 'lib/vagalume/search_result.rb', line 5

def initialize
  @translations = []
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



3
4
5
# File 'lib/vagalume/search_result.rb', line 3

def artist
  @artist
end

#songObject

Returns the value of attribute song.



3
4
5
# File 'lib/vagalume/search_result.rb', line 3

def song
  @song
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/vagalume/search_result.rb', line 3

def status
  @status
end

#translationsObject

Returns the value of attribute translations.



3
4
5
# File 'lib/vagalume/search_result.rb', line 3

def translations
  @translations
end

Class Method Details

.fetch(result_json) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagalume/search_result.rb', line 9

def self.fetch(result_json)
  result = Vagalume::SearchResult.new
  result.status = result_json["type"]
  return result if result.status == Vagalume::Status::NOT_FOUND || result.status == Vagalume::Status::SONG_NOT_FOUND
  song = result_json["mus"].first
  artist = result_json["art"]
  translations = song["translate"] || []
  result.song = Vagalume::Song.fetch(song)
  result.artist = Vagalume::Artist.fetch(artist)

  translations.each do |translation|
    result.translations << Vagalume::Song.fetch(translation)
  end
  result
end