class Lyricli::Lyricli
This class has the basic logic for extracting the lyrics and controlling the application
Public Class Methods
new()
click to toggle source
Constructor, initializes `@source_manager`
# File lib/lyricli/lyricli.rb, line 8 def initialize @source_manager = SourceManager.new end
Public Instance Methods
check_params()
click to toggle source
Exits with error when there is an empty field from the current track.
# File lib/lyricli/lyricli.rb, line 56 def check_params self.exit_with_error unless @current_track self.exit_with_error if @current_track[:artist].nil? or @current_track[:artist].empty? self.exit_with_error if @current_track[:song].nil? or @current_track[:song].empty? end
exit_with_error()
click to toggle source
Raises an InvalidLyricsError which means we did not get any valid artist/song from any of the sources
@raise [Lyricli::Exceptions::InvalidLyricsError] because we found nothing
# File lib/lyricli/lyricli.rb, line 16 def exit_with_error raise Exceptions::InvalidLyricsError end
get_lyrics(show_title=false)
click to toggle source
Extracts the current track, validates it and requests the lyrics from our LyricsEngine
@return [String] the found lyrics, or a string indicating none were found
# File lib/lyricli/lyricli.rb, line 24 def get_lyrics(show_title=false) begin set_current_track check_params rescue Exceptions::InvalidLyricsError return "No Artist/Song could be found :(" end engine = LyricsEngine.new(@current_track[:artist], @current_track[:song]) begin lyrics_output = engine.get_lyrics if show_title lyrics_title = "#{@current_track[:artist]} - #{@current_track[:song]}" lyrics_output = "#{lyrics_title}\n\n#{lyrics_output}" end return lyrics_output rescue Exceptions::LyricsNotFoundError return "Lyrics not found :(" end end
set_current_track()
click to toggle source
Set the `@current_track` instance variable by asking the SourceManager
for its current track
# File lib/lyricli/lyricli.rb, line 51 def set_current_track @current_track = @source_manager.current_track end