Class: Lyricli::Lyricli

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

Instance Method Summary (collapse)

Constructor Details

- (Lyricli) initialize

A new instance of Lyricli



4
5
6
# File 'lib/lyricli/lyricli.rb', line 4

def initialize
  @source_manager = SourceManager.new
end

Instance Method Details

- (Object) check_params



29
30
31
32
# File 'lib/lyricli/lyricli.rb', line 29

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:

  • (InvalidLyrics)


8
9
10
# File 'lib/lyricli/lyricli.rb', line 8

def exit_with_error
  raise InvalidLyrics
end

- (Object) get_lyrics



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lyricli/lyricli.rb', line 12

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



25
26
27
# File 'lib/lyricli/lyricli.rb', line 25

def set_current_track
  @current_track = @source_manager.current_track
end