]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/lyricli.rb
c3e1faecb94dd657a98bf78de7e1fe0b972d9b98
3 # This class has the basic logic for extracting the lyrics and controlling the
7 # Constructor, initializes `@source_manager`
9 @source_manager = SourceManager
.new
12 # Raises an InvalidLyricsError which means we did not get any valid
13 # artist/song from any of the sources
15 # @raise [Lyricli::Exceptions::InvalidLyricsError] because we found nothing
17 raise Exceptions
::InvalidLyricsError
20 # Extracts the current track, validates it and requests the lyrics from our
23 # @return [String] the found lyrics, or a string indicating none were found
29 rescue Exceptions
::InvalidLyricsError
30 return "No Artist/Song could be found :("
33 engine
= LyricsEngine
.new(@current_track[:artist], @current_track[:song])
36 return engine
.get_lyrics
37 rescue Exceptions
::LyricsNotFoundError
38 return "Lyrics not found :("
42 # Set the `@current_track` instance variable by asking the SourceManager for
45 @current_track = @source_manager.current_track
48 # Exits with error when there is an empty field from the current track.
50 self.exit_with_error
unless @current_track
51 self.exit_with_error
if @current_track[:artist].nil? or @current_track[:artist].empty
?
52 self.exit_with_error
if @current_track[:song].nil? or @current_track[:song].empty
?