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 InvalidLyricsError 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.
49 50 51 52 53 |
# File 'lib/lyricli/lyricli.rb', line 49 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 |
- (Object) exit_with_error
Raises an InvalidLyricsError 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 Exceptions::InvalidLyricsError 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 36 37 38 39 40 |
# File 'lib/lyricli/lyricli.rb', line 24 def get_lyrics 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 return engine.get_lyrics rescue Exceptions::LyricsNotFoundError return "Lyrics not found :(" end end |
- (Object) set_current_track
Set the `@current_track` instance variable by asking the SourceManager for its current track
44 45 46 |
# File 'lib/lyricli/lyricli.rb', line 44 def set_current_track @current_track = @source_manager.current_track end |