Class: Lyricli::Lyricli
- Inherits:
-
Object
- Object
- Lyricli::Lyricli
- Defined in:
- lib/lyricli/lyricli.rb
Overview
This class has the basic logic for extracting the lyrics and controlling the application
Instance Method Summary (collapse)
-
- (Object) check_params
Exits with error when there is an empty field from the current track.
-
- (Object) exit_with_error
Raises an InvalidLyricsException which means we did not get any valid artist/song from any of the sources.
-
- (String) get_lyrics
Extracts the current track, validates it and requests the lyrics from our LyricsEngine.
-
- (Lyricli) initialize
constructor
Constructor, initializes `@source_manager`.
-
- (Object) set_current_track
Set the `@current_track` instance variable by asking the SourceManager for its current track.
Constructor Details
- (Lyricli) initialize
Constructor, initializes `@source_manager`
8 9 10 |
# File 'lib/lyricli/lyricli.rb', line 8 def initialize @source_manager = SourceManager.new end |
Instance Method Details
- (Object) check_params
Exits with error when there is an empty field from the current track.
44 45 46 47 |
# File 'lib/lyricli/lyricli.rb', line 44 def check_params 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 |
- (Object) exit_with_error
Raises an InvalidLyricsException which means we did not get any valid artist/song from any of the sources
16 17 18 |
# File 'lib/lyricli/lyricli.rb', line 16 def exit_with_error raise InvalidLyricsException end |
- (String) get_lyrics
Extracts the current track, validates it and requests the lyrics from our LyricsEngine
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lyricli/lyricli.rb', line 24 def get_lyrics set_current_track check_params engine = LyricsEngine.new(@current_track[:artist], @current_track[:song]) begin engine.get_lyrics rescue LyricsNotFoundException "Lyrics not found :(" end end |
- (Object) set_current_track
Set the `@current_track` instance variable by asking the SourceManager for its current track
39 40 41 |
# File 'lib/lyricli/lyricli.rb', line 39 def set_current_track @current_track = @source_manager.current_track end |