]> git.r.bdr.sh - rbdr/lyricli.rb/commitdiff
Adds -t / --title option to show header
authorBen Beltran <redacted>
Fri, 14 Nov 2014 00:01:50 +0000 (17:01 -0700)
committerBen Beltran <redacted>
Fri, 14 Nov 2014 00:01:50 +0000 (17:01 -0700)
bin/lrc
lib/lyricli.rb
lib/lyricli/lyricli.rb

diff --git a/bin/lrc b/bin/lrc
index 3f71d87cc35212ea49a870c0f66d041d123b8503..19e54562f1e0fc0226b553b0ecb9a3be90743afd 100755 (executable)
--- a/bin/lrc
+++ b/bin/lrc
@@ -35,6 +35,10 @@ Options:
       exit
     end
 
+    opts.on("-t", "--title", "Shows the song title and artist") do
+      Lyricli.show_title
+    end
+
     opts.on("-h", "--help", "Shows this message") do
       puts opts
       exit
index 73c5811a0e7a102d39f34ea2057407efb050a8c7..e995c45945a115e36f756f6feef8539e1d5b249f 100755 (executable)
@@ -40,7 +40,7 @@ module Lyricli
   # @return [String] the fetched lyrics
   def self.lyrics
     @lyricli = Lyricli.new
-    @lyricli.get_lyrics
+    @lyricli.get_lyrics(@show_title)
   end
 
   # Returns the version of the library
@@ -93,4 +93,9 @@ module Lyricli
   def self.root
     File.expand_path('../..',__FILE__)
   end
+
+  # Sets the show_title instance variable so it requests the title
+  def self.show_title
+    @show_title = true
+  end
 end
index c3e1faecb94dd657a98bf78de7e1fe0b972d9b98..dfb627c8c0b68dd9569dcf73971bee1d64799a4c 100644 (file)
@@ -21,7 +21,7 @@ module Lyricli
     # LyricsEngine
     #
     # @return [String] the found lyrics, or a string indicating none were found
-    def get_lyrics
+    def get_lyrics(show_title=false)
 
       begin
         set_current_track
@@ -33,7 +33,14 @@ module Lyricli
       engine = LyricsEngine.new(@current_track[:artist], @current_track[:song])
 
       begin
-        return engine.get_lyrics
+        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