Class: MusixMatch::InstantLyrics::Search

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(q) ⇒ Search

Returns a new instance of Search.



16
17
18
# File 'lib/musix_match/instant_lyrics.rb', line 16

def initialize(q)
  @q = q
end

Class Method Details

.search(q) ⇒ Object



40
41
42
# File 'lib/musix_match/instant_lyrics.rb', line 40

def self.search(q)
  s = Search.new(q).start
end

Instance Method Details

#find_lyrics(track_id) ⇒ Object



33
34
35
36
37
38
# File 'lib/musix_match/instant_lyrics.rb', line 33

def find_lyrics(track_id)
  result = MusixMatch.get_lyrics(track_id)
  if result.status_code == 200 && lyrics = result.lyrics
    lyrics
  end
end

#search_trackObject



26
27
28
29
30
31
# File 'lib/musix_match/instant_lyrics.rb', line 26

def search_track
  result = MusixMatch.search_track(:q => @q, :f_has_lyrics => 1)
  if result.status_code == 200 && lyrics = result.track_list.first
    lyrics.track_id
  end
end

#startObject



20
21
22
23
24
# File 'lib/musix_match/instant_lyrics.rb', line 20

def start
  track_id = search_track
  lyrics    = find_lyrics(track_id) if track_id
  Result.new(lyrics)
end