From: Ben Beltran Date: Sat, 6 Oct 2012 07:35:48 +0000 (-0500) Subject: Finish first wave of documentation. X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/commitdiff_plain/f2ec7254120c90c3b023687f67a7b19f78b69370 Finish first wave of documentation. Also adds some stuff to the git ignore file --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb76b24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*.gem +*.rbc +.bundle +.config +coverage +InstalledFiles +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp + +# YARD artifacts +.yardoc +_yardoc +doc/ \ No newline at end of file diff --git a/.yardoc/checksums b/.yardoc/checksums index 475fe5a..b2fe954 100644 --- a/.yardoc/checksums +++ b/.yardoc/checksums @@ -1,9 +1,11 @@ lib/lyricli.rb 51e33086d1cbac6ccd601dd481a3b455376efb46 lib/lyricli/util.rb 26284bcf3521994d5f81c5f10a750dad8fda1593 -lib/lyricli/lyricli.rb 067ba6355bce4ce18cc5552580b91b4e266250a2 -lib/lyricli/sources/rdio.rb affae043fecd57d068a54a710718d19933d53b81 -lib/lyricli/lyrics_engine.rb be6feb81f3c3c040420d1fb33df4d1282a959d15 -lib/lyricli/configuration.rb eab80327c885fe827811de01de1e9e64c312b0c0 -lib/lyricli/sources/itunes.rb 8f0b1201051be95df66f8a94554e393681795eb7 -lib/lyricli/source_manager.rb fd571d1c1a169f86efed5c886b40f912fb5ad01f -lib/lyricli/sources/arguments.rb de3b31f05d118cf00fccb41e47fd35979da9eb14 +lib/lyricli/lyricli.rb 5a966a6402b5646b2c755cf79c3f7006b4a6d818 +lib/lyricli/sources.rb 69d670f2d008827b861dcd543caad3986ccc323e +lib/lyricli/exceptions.rb 943e408e869981dded31cd236da1da937e6b0574 +lib/lyricli/sources/rdio.rb 8936e4de676719c26fe6b8fcf2396b85d5723996 +lib/lyricli/lyrics_engine.rb 9ebc53647e5be739ce8a0fe1e7d10fbce02d7083 +lib/lyricli/configuration.rb f08b1caf4dffacccf888c5b22e4a8e3107f004d6 +lib/lyricli/sources/itunes.rb aadca88a9ad0d0b4c918d86874f403d10ec3add7 +lib/lyricli/source_manager.rb d16a3e3592f48dbda8adbef1b1cfe49a9dc42617 +lib/lyricli/sources/arguments.rb fa19b956453041cf5df0402142cbe073f2c9e686 diff --git a/.yardoc/object_types b/.yardoc/object_types index dbe4c58..1ed18b4 100644 Binary files a/.yardoc/object_types and b/.yardoc/object_types differ diff --git a/.yardoc/objects/root.dat b/.yardoc/objects/root.dat index 9c94980..8522ce3 100644 Binary files a/.yardoc/objects/root.dat and b/.yardoc/objects/root.dat differ diff --git a/doc/Lyricli.html b/doc/Lyricli.html index 8a09e7f..d757eac 100644 --- a/doc/Lyricli.html +++ b/doc/Lyricli.html @@ -80,7 +80,7 @@
Defined in:
lib/lyricli.rb,
- lib/lyricli/util.rb,
lib/lyricli/lyricli.rb,
lib/lyricli/sources/rdio.rb,
lib/lyricli/lyrics_engine.rb,
lib/lyricli/configuration.rb,
lib/lyricli/sources/itunes.rb,
lib/lyricli/source_manager.rb,
lib/lyricli/sources/arguments.rb
+ lib/lyricli/util.rb,
lib/lyricli/lyricli.rb,
lib/lyricli/sources.rb,
lib/lyricli/exceptions.rb,
lib/lyricli/sources/rdio.rb,
lib/lyricli/lyrics_engine.rb,
lib/lyricli/configuration.rb,
lib/lyricli/sources/itunes.rb,
lib/lyricli/source_manager.rb,
lib/lyricli/sources/arguments.rb
@@ -103,7 +103,7 @@ song and artist data from diverse sources.

- Modules: Sources, Util + Modules: Exceptions, Sources, Util @@ -611,7 +611,7 @@ the version

diff --git a/doc/Lyricli/Configuration.html b/doc/Lyricli/Configuration.html index 77112a3..f2fa54d 100644 --- a/doc/Lyricli/Configuration.html +++ b/doc/Lyricli/Configuration.html @@ -99,7 +99,19 @@
+

Overview

+
+

+This class handles the configuration of Lyricli +

+ + +
+
+
+ +

Constant Summary

@@ -143,7 +155,10 @@ -
+

+Ensure this is only called once. +

+
@@ -160,7 +175,7 @@
  • - - (Object) [](key) + - (String, ...) [](key) @@ -174,7 +189,10 @@ -
    +

    +Access configuration properties, loads config if needed beforehand. +

    +
  • @@ -196,7 +214,11 @@ -
    +

    +Assigns a new value to a configuration key, loads config if needed and +saves it after updating. +

    +
    @@ -218,7 +240,11 @@ -
    +

    +Deletes a key from the configuration, loads config if needed and saves it +after deleting. +

    +
    @@ -243,7 +269,7 @@

    -A new instance of Configuration. +Defines the paths to the default and user configuration files.

    @@ -268,7 +294,8 @@ A new instance of Configuration.

    -TODO: Apart from this, load a default yml that will be used for this. +Loads the configuration from the user file, attempts to create it from +defaults if it’s not present.

    @@ -292,7 +319,10 @@ TODO: Apart from this, load a default yml that will be used for this. -
    +

    +Serializes the `@config` Hash to JSON and saves it to a file. +

    +
    @@ -315,7 +345,7 @@ TODO: Apart from this, load a default yml that will be used for this.

    -A new instance of Configuration +Defines the paths to the default and user configuration files

    @@ -330,14 +360,14 @@ A new instance of Configuration
     
     
    -4
    -5
    -6
     7
    -8
    +8 +9 +10 +11 -
    # File 'lib/lyricli/configuration.rb', line 4
    +      
    # File 'lib/lyricli/configuration.rb', line 7
     
     def initialize
       @config_path = "~/.lyricli.conf"
    @@ -365,18 +395,31 @@ A new instance of Configuration
       
     
       
    -
    +
    +
    +

    +Ensure this is only called once. Only use the instance class variable to +access this method, as its constructor is private. +

    + + +
    +
    +
    + + +
     
     
    -12
    -13
    -14
    +17 +18 +19
    -
    # File 'lib/lyricli/configuration.rb', line 12
    +      
    # File 'lib/lyricli/configuration.rb', line 17
     
     def self.instance
       @@instance
    @@ -395,25 +438,77 @@ A new instance of Configuration
           

    - - (Object) [](key) + - (String, ...) [](key) + + +

    +
    +

    +Access configuration properties, loads config if needed beforehand. +

    + +
    +
    +
    +

    Parameters:

    +
      - +
    • + + key + + + (String) + + + + — +

      +the configuration key to access +

      +
      + +
    • + + + +

      Returns:

      +
        + +
      • + + + (String, Hash, Array) + + + + — +

        +the value of the configuration key. +

        +
        + +
      • + +
      + +
       
       
      -16
      -17
      -18
      -19
      +25 +26 +27 +28
      -
      # File 'lib/lyricli/configuration.rb', line 16
      +      
      # File 'lib/lyricli/configuration.rb', line 25
       
       def [](key)
         load_config unless @config
      @@ -433,20 +528,72 @@ A new instance of Configuration
         
       
         
      -
      +
      +
      +

      +Assigns a new value to a configuration key, loads config if needed and +saves it after updating. +

      + + +
      +
      +
      +

      Parameters:

      +
        + +
      • + + key + + + (String) + + + + — +

        +the configuration key to set +

        +
        + +
      • + +
      • + + value + + + (Object) + + + + — +

        +the value for the configuration key, can be any object as long as it can be +converted to JSON +

        +
        + +
      • + +
      + + +
       
       
      -21
      -22
      -23
      -24
      -25
      +36 +37 +38 +39 +40
      -
      # File 'lib/lyricli/configuration.rb', line 21
      +      
      # File 'lib/lyricli/configuration.rb', line 36
       
       def []=(key, value)
         load_config unless @config
      @@ -467,20 +614,54 @@ A new instance of Configuration
         
       
         
      -
      +
      +
      +

      +Deletes a key from the configuration, loads config if needed and saves it +after deleting. +

      + + +
      +
      +
      +

      Parameters:

      +
        + +
      • + + key + + + (String) + + + + — +

        +the key to delete +

        +
        + +
      • + +
      + + +
       
       
      -27
      -28
      -29
      -30
      -31
      +46 +47 +48 +49 +50
      -
      # File 'lib/lyricli/configuration.rb', line 27
      +      
      # File 'lib/lyricli/configuration.rb', line 46
       
       def delete(key)
         load_config unless @config
      @@ -504,8 +685,8 @@ A new instance of Configuration
       

      -TODO: Apart from this, load a default yml that will be used for this. And -just extend everything from the user’s config. +Loads the configuration from the user file, attempts to create it from +defaults if it’s not present. sets the `@config` instance variable.

      @@ -520,19 +701,19 @@ just extend everything from the user’s config.
       
       
      -37
      -38
      -39
      -40
      -41
      -42
      -43
      -44
      -45
      -46
      +56 +57 +58 +59 +60 +61 +62 +63 +64 +65
      -
      # File 'lib/lyricli/configuration.rb', line 37
      +      
      # File 'lib/lyricli/configuration.rb', line 56
       
       def load_config
         path = File.expand_path(@config_path)
      @@ -558,21 +739,33 @@ just extend everything from the user’s config.
         
       
         
      -
      +
      +
      +

      +Serializes the `@config` Hash to JSON and saves it to a file. +

      + + +
      +
      +
      + + +
       
       
      -48
      -49
      -50
      -51
      -52
      -53
      +68 +69 +70 +71 +72 +73
      -
      # File 'lib/lyricli/configuration.rb', line 48
      +      
      # File 'lib/lyricli/configuration.rb', line 68
       
       def save_config
         path = File.expand_path(@config_path)
      @@ -590,7 +783,7 @@ just extend everything from the user’s config.
       
       
           
      diff --git a/doc/Lyricli/Exceptions.html b/doc/Lyricli/Exceptions.html
      new file mode 100644
      index 0000000..f6acefd
      --- /dev/null
      +++ b/doc/Lyricli/Exceptions.html
      @@ -0,0 +1,117 @@
      +
      +
      +  
      +    
      +
      +  Module: Lyricli::Exceptions
      +  
      +    — Documentation by YARD 0.8.2.1
      +  
      +
      +
      +  
      +
      +  
      +
      +
      +
      +
      +  
      +
      +  
      +
      +
      +  
      +  
      +    
      +
      +    
      +
      +    

      Module: Lyricli::Exceptions + + + +

      + +
      + + + + + + + + +
      Defined in:
      +
      lib/lyricli/exceptions.rb
      + +
      +
      + +

      Overview

      +
      +

      +The namespace for all exceptions in Lyricli. Has no functionality by itself +

      + + +
      +
      +
      + + +
      + + + + + + + + +
      + + + + + \ No newline at end of file diff --git a/doc/Lyricli/Lyricli.html b/doc/Lyricli/Lyricli.html index 090262d..60c3a94 100644 --- a/doc/Lyricli/Lyricli.html +++ b/doc/Lyricli/Lyricli.html @@ -99,8 +99,21 @@
      +

      Overview

      +
      +

      +This class has the basic logic for extracting the lyrics and controlling +the application +

      +
      +
      +
      + + +
      + @@ -131,7 +144,10 @@ -
      +

      +Exits with error when there is an empty field from the current track. +

      +
      @@ -153,7 +169,11 @@ -
      +

      +Raises an InvalidLyricsException which means we did not get any valid +artist/song from any of the sources. +

      +
      @@ -161,7 +181,7 @@
    • - - (Object) get_lyrics + - (String) get_lyrics @@ -175,7 +195,11 @@ -
      +

      +Extracts the current track, validates it and requests the lyrics from our +LyricsEngine. +

      +
    • @@ -200,7 +224,7 @@

      -A new instance of Lyricli. +Constructor, initializes `@source_manager`.

      @@ -224,7 +248,11 @@ A new instance of Lyricli. -
      +

      +Set the `@current_track` instance variable by asking the SourceManager for +its current track. +

      +
      @@ -247,7 +275,7 @@ A new instance of Lyricli.

      -A new instance of Lyricli +Constructor, initializes `@source_manager`

      @@ -262,12 +290,12 @@ A new instance of Lyricli
       
       
      -4
      -5
      -6
      +8 +9 +10
      -
      # File 'lib/lyricli/lyricli.rb', line 4
      +      
      # File 'lib/lyricli/lyricli.rb', line 8
       
       def initialize
         @source_manager = SourceManager.new
      @@ -293,19 +321,31 @@ A new instance of Lyricli
         
       
         
      -
      +
      +
      +

      +Exits with error when there is an empty field from the current track. +

      + + +
      +
      +
      + + +
      @@ -371,33 +421,65 @@ A new instance of Lyricli

      - - (Object) get_lyrics + - (String) get_lyrics -

       
       
      -29
      -30
      -31
      -32
      +44 +45 +46 +47
      -
      # File 'lib/lyricli/lyricli.rb', line 29
      +      
      # File 'lib/lyricli/lyricli.rb', line 44
       
       def check_params
         self.exit_with_error if @current_track[:artist].nil? or @current_track[:artist].empty?
      @@ -327,7 +367,11 @@ A new instance of Lyricli
         
       
      - +

      +Raises an InvalidLyricsException which means we did not get any valid +artist/song from any of the sources +

      +
      @@ -339,9 +383,15 @@ A new instance of Lyricli
    • - (InvalidLyrics) + (Lyricli::InvalidLyricsException) + + — +

      +because we found nothing +

      +
    • @@ -353,15 +403,15 @@ A new instance of Lyricli
       
       
      -8
      -9
      -10
      +16 +17 +18
      -
      # File 'lib/lyricli/lyricli.rb', line 8
      +      
      # File 'lib/lyricli/lyricli.rb', line 16
       
       def exit_with_error
      -  raise InvalidLyrics
      +  raise InvalidLyricsException
       end
      +
      +
      +

      +Extracts the current track, validates it and requests the lyrics from our +LyricsEngine +

      + + +
      +
      +
      + +

      Returns:

      +
        + +
      • + + + (String) + + + + — +

        +the found lyrics, or a string indicating none were found +

        +
        + +
      • + +
      + +
       
       
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      -23
      +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35
      -
      # File 'lib/lyricli/lyricli.rb', line 12
      +      
      # File 'lib/lyricli/lyricli.rb', line 24
       
       def get_lyrics
         set_current_track
      @@ -425,18 +507,31 @@ A new instance of Lyricli
         
       
         
      -
      +
      +
      +

      +Set the `@current_track` instance variable by asking the SourceManager for +its current track +

      + + +
      +
      +
      + + +
       
       
      -25
      -26
      -27
      +39 +40 +41
      -
      # File 'lib/lyricli/lyricli.rb', line 25
      +      
      # File 'lib/lyricli/lyricli.rb', line 39
       
       def set_current_track
         @current_track = @source_manager.current_track
      @@ -451,7 +546,7 @@ A new instance of Lyricli
       
       
           
      diff --git a/doc/Lyricli/LyricsEngine.html b/doc/Lyricli/LyricsEngine.html
      index 23a5f73..0efd283 100644
      --- a/doc/Lyricli/LyricsEngine.html
      +++ b/doc/Lyricli/LyricsEngine.html
      @@ -103,8 +103,20 @@
       
       
      +

      Overview

      +
      +

      +This class gets the lyrics according to a given artist and song name. +

      +
      +
      +
      + + +
      + @@ -121,7 +133,7 @@
    • - - (Object) get_lyrics + - (String) get_lyrics @@ -135,7 +147,10 @@ -
      +

      +Asks Lyrics Wiki for the lyrics, also cleans up the output a little. +

      +
    • @@ -160,7 +175,7 @@

      -A new instance of LyricsEngine. +Starts a new instance of LyricsEngine.

      @@ -196,14 +211,52 @@ A new instance of LyricsEngine.

      -A new instance of LyricsEngine +Starts a new instance of LyricsEngine

      +

      Parameters:

      +
        + +
      • + + artist + + + (String) + + + + — +

        +the artist +

        +
        + +
      • + +
      • + + song + + + (String) + + + + — +

        +the song to look for +

        +
        + +
      • +
      +
      @@ -211,12 +264,12 @@ A new instance of LyricsEngine
       
       
      -6
      -7
      -8
      +12 +13 +14
      -
      # File 'lib/lyricli/lyrics_engine.rb', line 6
      +      
      # File 'lib/lyricli/lyrics_engine.rb', line 12
       
       def initialize(artist, song)
         @provider = URI("http://lyrics.wikia.com/api.php?artist=#{sanitize_param artist}&song=#{sanitize_param song}&fmt=realjson")
      @@ -236,27 +289,49 @@ A new instance of LyricsEngine
             

      - - (Object) get_lyrics + - (String) get_lyrics -

      +
      +
      +

      +Asks Lyrics Wiki for the lyrics, also cleans up the output a little. +

      + + +
      +
      +
      + +

      Returns:

      +
        + +
      • + + + (String) + + + + — +

        +the lyrics +

        +
        + +
      • + +
      + +
       
       
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
       19
       20
       21
      @@ -268,10 +343,19 @@ A new instance of LyricsEngine
       27
       28
       29
      -30
      +30 +31 +32 +33 +34 +35 +36 +37 +38 +39
      -
      # File 'lib/lyricli/lyrics_engine.rb', line 10
      +      
      # File 'lib/lyricli/lyrics_engine.rb', line 19
       
       def get_lyrics
         begin
      @@ -304,7 +388,7 @@ A new instance of LyricsEngine
       
       
           
      diff --git a/doc/Lyricli/SourceManager.html b/doc/Lyricli/SourceManager.html
      index 2f48f97..3a37bc4 100644
      --- a/doc/Lyricli/SourceManager.html
      +++ b/doc/Lyricli/SourceManager.html
      @@ -103,7 +103,20 @@
       
       
      +

      Overview

      +
      +

      +Manages the different sources. SourceManager is in charge of enabling and +disabling them, as well as getting the current track. +

      + + +
      +
      +
      + +
      @@ -121,7 +134,7 @@
    • - - (Object) available_sources(format = false) + - (Array) available_sources(format = false) @@ -135,7 +148,10 @@ -
      +

      +Returns an array with the available sources. +

      +
    • @@ -143,7 +159,7 @@
    • - - (Object) current_track + - (Hash) current_track @@ -157,7 +173,10 @@ -
      +

      +Iterates over every source to attempt to retrieve the current song. +

      +
    • @@ -179,7 +198,10 @@ -
      +

      +Disables a source. +

      +
      @@ -201,7 +223,10 @@ -
      +

      +Enables a source. +

      +
      @@ -209,7 +234,7 @@
    • - - (Object) format_sources(sources) + - (Array) format_sources(sources) @@ -223,7 +248,11 @@ -
      +

      +Adds a star to all members of the array that correspond to an active +source. +

      +
    • @@ -248,7 +277,7 @@

      -A new instance of SourceManager. +Creates a new instance of SourceManager.

      @@ -272,7 +301,10 @@ A new instance of SourceManager. -
      +

      +Resets a source. +

      +
      @@ -306,7 +338,7 @@ A new instance of SourceManager.

      -A new instance of SourceManager +Creates a new instance of SourceManager

      @@ -321,10 +353,6 @@ A new instance of SourceManager
       
       
      -6
      -7
      -8
      -9
       10
       11
       12
      @@ -332,10 +360,14 @@ A new instance of SourceManager
       14
       15
       16
      -17
      +17 +18 +19 +20 +21
      -
      # File 'lib/lyricli/source_manager.rb', line 6
      +      
      # File 'lib/lyricli/source_manager.rb', line 10
       
       def initialize
         @enabled_sources = []
      @@ -364,52 +396,105 @@ A new instance of SourceManager
             

      - - (Object) available_sources(format = false) + - (Array) available_sources(format = false) + + +

      +
      +

      +Returns an array with the available sources. Optionally formats the result +so active sources are identified by an appended * +

      + + +
      +
      +
      +

      Parameters:

      +
        + +
      • + + format + + + (Boolean) + + + (defaults to: false) + + + — +

        +whether or not to render the stars for active sources. +

        +
        + +
      • + +
      +

      Returns:

      +
        + +
      • + + + (Array) + + + + — +

        +the names of the currently available sources. +

        +
        + +
      • - + + +
         
         
        -81
        -82
        -83
        -84
        -85
        -86
        -87
        -88
        -89
        -90
        -91
        -92
        -93
        -94
        -95
        -96
        -97
        +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122
        -
        # File 'lib/lyricli/source_manager.rb', line 81
        +      
        # File 'lib/lyricli/source_manager.rb', line 107
         
         def available_sources(format = false)
           path_root = File.expand_path(File.dirname(__FILE__))
           sources = Dir[path_root+"/sources/*.rb"].map{ |s|
             name = s.split("/").last.gsub(/\.rb/, "")
        -
        -    # Add a star to denote enabled sources
        -    name
        +    name
           }
         
           # Remove arguments (Hack?) We don't want anybody to touch tihs one.
           sources.delete("arguments")
           if format
        -    format_sources(sources)
        +    # Add a star to denote enabled sources
        +    format_sources(sources)
           else
             sources
           end
        @@ -422,41 +507,72 @@ A new instance of SourceManager
               

        - - (Object) current_track + - (Hash) current_track -

        +
        +
        +

        +Iterates over every source to attempt to retrieve the current song. +

        + + +
        +
        +
        + +

        Returns:

        +
          + +
        • + + + (Hash) + + + + — +

          +the current track, has an `:artist` and `:song` key. +

          +
          + +
        • + +
        + +
         
         
        -60
        -61
        -62
        -63
        -64
        -65
        -66
        -67
        -68
        -69
        -70
        -71
        -72
        -73
        -74
        -75
        -76
        -77
        -78
        -79
        +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99
        -
        # File 'lib/lyricli/source_manager.rb', line 60
        +      
        # File 'lib/lyricli/source_manager.rb', line 80
         
         def current_track
           track = nil
        @@ -492,27 +608,61 @@ A new instance of SourceManager
           
         
           
        -
        +
        +
        +

        +Disables a source. This only removes the source from the `enabled_sources` +configuration key. +

        + + +
        +
        +
        +

        Parameters:

        +
          + +
        • + + source_name + + + (String) + + + + — +

          +the name of the source to disable +

          +
          + +
        • + +
        + + +
         
         
        -34
        -35
        -36
        -37
        -38
        -39
        -40
        -41
        -42
        -43
        -44
        -45
        +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58
        -
        # File 'lib/lyricli/source_manager.rb', line 34
        +      
        # File 'lib/lyricli/source_manager.rb', line 47
         
         def disable(source_name)
           if available_sources.include?(source_name)
        @@ -540,29 +690,64 @@ A new instance of SourceManager
           
         
           
        -
        +
        +
        +

        +Enables a source. This runs the source’s enable method and adds it to +the `enabled_sources` configuration key. It will only enable sources that +are “available” (see #available_sources) +

        + + +
        +
        +
        +

        Parameters:

        +
          + +
        • + + source_name + + + (String) + + + + — +

          +the name of the source to enable +

          +
          + +
        • + +
        + + +
         
         
        -19
        -20
        -21
        -22
        -23
        -24
        -25
        -26
        -27
         28
         29
         30
         31
        -32
        +32 +33 +34 +35 +36 +37 +38 +39 +40 +41
        -
        # File 'lib/lyricli/source_manager.rb', line 19
        +      
        # File 'lib/lyricli/source_manager.rb', line 28
         
         def enable(source_name)
           if available_sources.include?(source_name)
        @@ -586,27 +771,79 @@ A new instance of SourceManager
               

        - - (Object) format_sources(sources) + - (Array) format_sources(sources) -

        +
        +
        +

        +Adds a star to all members of the array that correspond to an active source +

        + + +
        +
        +
        +

        Parameters:

        +
          + +
        • + + sources + + + (Array) + + + + — +

          +the array of sources to format +

          +
          + +
        • + +
        + +

        Returns:

        +
          + +
        • + + + (Array) + + + + — +

          +the formatted array +

          +
          + +
        • + +
        + +
         
         
        -99
        -100
        -101
        -102
        -103
        -104
        +129 +130 +131 +132 +133 +134
        -
        # File 'lib/lyricli/source_manager.rb', line 99
        +      
        # File 'lib/lyricli/source_manager.rb', line 129
         
         def format_sources(sources)
           sources.map{ |s|
        @@ -628,27 +865,61 @@ A new instance of SourceManager
           
         
           
        -
        +
        +
        +

        +Resets a source. This runs the source’s reset method. It will also +disable them. +

        + + +
        +
        +
        +

        Parameters:

        +
          + +
        • + + source_name + + + (String) + + + + — +

          +the name of the source to reset. +

          +
          + +
        • + +
        + + +
         
         
        -47
        -48
        -49
        -50
        -51
        -52
        -53
        -54
        -55
        -56
        -57
        -58
        +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75
        -
        # File 'lib/lyricli/source_manager.rb', line 47
        +      
        # File 'lib/lyricli/source_manager.rb', line 64
         
         def reset(source_name)
           if available_sources.include?(source_name)
        @@ -672,7 +943,7 @@ A new instance of SourceManager
         
         
             
        diff --git a/doc/Lyricli/Sources.html b/doc/Lyricli/Sources.html
        index ad3a5a1..518014a 100644
        --- a/doc/Lyricli/Sources.html
        +++ b/doc/Lyricli/Sources.html
        @@ -79,14 +79,26 @@
           
           
             
        Defined in:
        -
        lib/lyricli/sources/rdio.rb,
        - lib/lyricli/sources/itunes.rb,
        lib/lyricli/sources/arguments.rb
        +
        lib/lyricli/sources.rb,
        + lib/lyricli/sources/rdio.rb,
        lib/lyricli/sources/itunes.rb,
        lib/lyricli/sources/arguments.rb
        -

        Defined Under Namespace

        +

        Overview

        +
        +

        +The namespace for all sources in Lyricli. Has no functionality by itself +

        + + +
        +
        +
        + + +

        Defined Under Namespace

        @@ -108,7 +120,7 @@

        diff --git a/doc/Lyricli/Sources/Arguments.html b/doc/Lyricli/Sources/Arguments.html index 6f0be65..934a4a7 100644 --- a/doc/Lyricli/Sources/Arguments.html +++ b/doc/Lyricli/Sources/Arguments.html @@ -99,7 +99,20 @@
        +

        Overview

        +
        +

        +The arguments source. This one is special since it expects two arguments. +It is treated specially by the SourceManager. +

        + + +
        +
        +
        + +
        @@ -293,12 +306,12 @@ Instantiates everything it needs to run.
         
         
        -18
        -19
        -20
        +20 +21 +22
        -
        # File 'lib/lyricli/sources/arguments.rb', line 18
        +      
        # File 'lib/lyricli/sources/arguments.rb', line 20
         
         def initialize
           # Nothing to do.
        @@ -342,12 +355,12 @@ Returns the value of attribute name
               
         
         
        -6
        -7
        -8
        +8 +9 +10
        -
        # File 'lib/lyricli/sources/arguments.rb', line 6
        +      
        # File 'lib/lyricli/sources/arguments.rb', line 8
         
         def name
           @name
        @@ -392,12 +405,12 @@ source. In the case of Rdio it has to authenticate with OAuth.
               
         
         
        -13
        -14
        -15
        +15 +16 +17
        -
        # File 'lib/lyricli/sources/arguments.rb', line 13
        +      
        # File 'lib/lyricli/sources/arguments.rb', line 15
         
         def self.enable
           # Nothing to do.
        @@ -434,12 +447,12 @@ The reset method resets any configurations it may have
               
         
         
        -32
        -33
        -34
        +34 +35 +36
        -
        # File 'lib/lyricli/sources/arguments.rb', line 32
        +      
        # File 'lib/lyricli/sources/arguments.rb', line 34
         
         def self.reset
           # Reset Code
        @@ -502,14 +515,14 @@ A hash containing the current `:song` and `:artist`.
               
         
         
        -25
        -26
         27
         28
        -29
        +29 +30 +31
        -
        # File 'lib/lyricli/sources/arguments.rb', line 25
        +      
        # File 'lib/lyricli/sources/arguments.rb', line 27
         
         def current_track
           artist = ARGV[0]
        @@ -526,7 +539,7 @@ A hash containing the current `:song` and `:artist`.
         
         
             
        diff --git a/doc/Lyricli/Sources/Itunes.html b/doc/Lyricli/Sources/Itunes.html
        new file mode 100644
        index 0000000..349f118
        --- /dev/null
        +++ b/doc/Lyricli/Sources/Itunes.html
        @@ -0,0 +1,553 @@
        +
        +
        +  
        +    
        +
        +  Class: Lyricli::Sources::Itunes
        +  
        +    — Documentation by YARD 0.8.2.1
        +  
        +
        +
        +  
        +
        +  
        +
        +
        +
        +
        +  
        +
        +  
        +
        +
        +  
        +  
        +    
        +
        +    
        +
        +    

        Class: Lyricli::Sources::Itunes + + + +

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

        Overview

        +
        +

        +The source for iTunes +

        + + +
        +
        +
        + + +
        + + + +

        Class Attribute Summary (collapse)

        +
          + +
        • + + + + (Object) name + + + + + + + + + + + + + + + + +

          +Returns the value of attribute name. +

          +
          + +
        • + + +
        + + + + + +

        + Class Method Summary + (collapse) +

        + +
          + +
        • + + + + (Object) enable + + + + + + + + + + + + + +

          +The enable method should run all of the tasks needed to validate the +source. +

          +
          + +
        • + + +
        • + + + + (Object) reset + + + + + + + + + + + + + +

          +The reset method resets any configurations it may have. +

          +
          + +
        • + + +
        + +

        + Instance Method Summary + (collapse) +

        + +
          + +
        • + + + - (Hash) current_track + + + + + + + + + + + + + +

          +The current_track method should return the name of the current artist and +song. +

          +
          + +
        • + + +
        • + + + - (Itunes) initialize + + + + + + + constructor + + + + + + + + +

          +Instantiates everything it needs to run. +

          +
          + +
        • + + +
        + + +
        +

        Constructor Details

        + +
        +

        + + - (Itunes) initialize + + + + + +

        +
        +

        +Instantiates everything it needs to run. +

        + + +
        +
        +
        + + +
        + + + + +
        +
        +
        +
        +19
        +20
        +21
        +22
        +
        +
        # File 'lib/lyricli/sources/itunes.rb', line 19
        +
        +def initialize
        +  @config = Configuration.instance
        +  @script = "current_song.scpt"
        +end
        +
        +
        + +
        + +
        +

        Class Attribute Details

        + + + +
        +

        + + + (Object) name + + + + + +

        +
        +

        +Returns the value of attribute name +

        + + +
        +
        +
        + + +
        + + + + +
        +
        +
        +
        +7
        +8
        +9
        +
        +
        # File 'lib/lyricli/sources/itunes.rb', line 7
        +
        +def name
        +  @name
        +end
        +
        +
        + +
        + + +
        +

        Class Method Details

        + + +
        +

        + + + (Object) enable + + + + + +

        +
        +

        +The enable method should run all of the tasks needed to validate the +source. In the case of Rdio it has to authenticate with OAuth. +

        + + +
        +
        +
        + + +
        + + + + +
        +
        +
        +
        +14
        +15
        +16
        +
        +
        # File 'lib/lyricli/sources/itunes.rb', line 14
        +
        +def self.enable
        +  # Nothing to do
        +end
        +
        +
        + +
        +

        + + + (Object) reset + + + + + +

        +
        +

        +The reset method resets any configurations it may have +

        + + +
        +
        +
        + + +
        + + + + +
        +
        +
        +
        +36
        +37
        +38
        +
        +
        # File 'lib/lyricli/sources/itunes.rb', line 36
        +
        +def self.reset
        +  # Nothing to do
        +end
        +
        +
        + +
        + +
        +

        Instance Method Details

        + + +
        +

        + + - (Hash) current_track + + + + + +

        +
        +

        +The current_track method should return the name of the current artist and +song. +

        + + +
        +
        +
        + +

        Returns:

        +
          + +
        • + + + (Hash) + + + + — +

          +A hash containing the current `:song` and `:artist`. +

          +
          + +
        • + +
        + +
        + + + + +
        +
        +
        +
        +27
        +28
        +29
        +30
        +31
        +32
        +33
        +
        +
        # File 'lib/lyricli/sources/itunes.rb', line 27
        +
        +def current_track
        +  path_root = File.expand_path(File.dirname(__FILE__))
        +  path = File.join(path_root, @script)
        +  current = `osascript #{path}`
        +  current = current.split("<-SEP->")
        +  {artist: current[0], song: current[1]}
        +end
        +
        +
        + +
        + +
        + + + + + \ No newline at end of file diff --git a/doc/Lyricli/Sources/Rdio.html b/doc/Lyricli/Sources/Rdio.html index 51ce909..3336a24 100644 --- a/doc/Lyricli/Sources/Rdio.html +++ b/doc/Lyricli/Sources/Rdio.html @@ -99,7 +99,19 @@
        +

        Overview

        +
        +

        +This is the Source for rdio +

        + + +
        +
        +
        + +
        @@ -319,14 +331,14 @@ Instantiates everything it needs to run.
         
         
        -27
        -28
         29
         30
        -31
        +31 +32 +33
        -
        # File 'lib/lyricli/sources/rdio.rb', line 27
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 29
         
         def initialize
           @name = 'rdio'
        @@ -372,12 +384,12 @@ Returns the value of attribute name
               
         
         
        -6
        -7
        -8
        +8 +9 +10
        -
        # File 'lib/lyricli/sources/rdio.rb', line 6
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 8
         
         def name
           @name
        @@ -422,9 +434,6 @@ token.
               
         
         
        -51
        -52
        -53
         54
         55
         56
        @@ -438,10 +447,13 @@ token.
         64
         65
         66
        -67
        +67 +68 +69 +70
        -
        # File 'lib/lyricli/sources/rdio.rb', line 51
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 54
         
         def self.create_auth_token
           rdio = ::Rdio::SimpleRdio.new([@config["rdio_key"], @config["rdio_secret"]], @config["rdio_auth_token"])
        @@ -493,8 +505,6 @@ source. In the case of Rdio it has to authenticate with OAuth.
               
         
         
        -13
        -14
         15
         16
         17
        @@ -504,10 +514,12 @@ source. In the case of Rdio it has to authenticate with OAuth.
         21
         22
         23
        -24
        +24 +25 +26
        -
        # File 'lib/lyricli/sources/rdio.rb', line 13
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 15
         
         def self.enable
           # Validation Code
        @@ -553,13 +565,13 @@ The reset method resets any configurations it may have
               
         
         
        -44
        -45
        -46
        -47
        +47 +48 +49 +50
        -
        # File 'lib/lyricli/sources/rdio.rb', line 44
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 47
         
         def self.reset
           @config = Configuration.instance
        @@ -623,15 +635,15 @@ A hash containing the current `:song` and `:artist`.
               
         
         
        -36
        -37
        -38
         39
         40
        -41
        +41 +42 +43 +44
        -
        # File 'lib/lyricli/sources/rdio.rb', line 36
        +      
        # File 'lib/lyricli/sources/rdio.rb', line 39
         
         def current_track
           response = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'})
        @@ -649,7 +661,7 @@ A hash containing the current `:song` and `:artist`.
         
         
             
        diff --git a/doc/Lyricli/Util.html b/doc/Lyricli/Util.html
        index b1a24d6..a126af5 100644
        --- a/doc/Lyricli/Util.html
        +++ b/doc/Lyricli/Util.html
        @@ -464,7 +464,7 @@ the sanitized parameter
         
         
             
        diff --git a/doc/_index.html b/doc/_index.html
        index d505ea5..681baf6 100644
        --- a/doc/_index.html
        +++ b/doc/_index.html
        @@ -110,6 +110,21 @@
                 
               
                 
        +        
        +      
        +        
                 
        • I
          • @@ -189,6 +204,9 @@
          +
        + +
        • U
          • @@ -212,7 +230,7 @@ diff --git a/doc/class_list.html b/doc/class_list.html index ca6a9fe..598a4a4 100644 --- a/doc/class_list.html +++ b/doc/class_list.html @@ -45,7 +45,7 @@ diff --git a/doc/file.README.html b/doc/file.README.html new file mode 100644 index 0000000..efaa475 --- /dev/null +++ b/doc/file.README.html @@ -0,0 +1,143 @@ + + + + + + File: README + + — Documentation by YARD 0.8.2.1 + + + + + + + + + + + + + + + + + + + + + +

            Lyricli

            + +

            The command line client for lyrics

            + +

            This is a quick introduction for Lyricli. Right now it's in really early +stages of development, so it's lacking in a lot of stuff (mainly tests +and documentation) ... But it generally works and here's a tutorial to +see how to get it working.

            + +

            Installing

            + +
              +
            1. Clone this Repo
            2. +
            3. gem build lyricli.gemspec
            4. +
            5. gem install lyricli-0.0.1.gem
            6. +
            7. Voila!
            8. +
            + +

            Usage

            + +

            Lyricli can be invoked with the command lrc and there are three basic +ways of using it:

            + +

            lrc

            + +

            When you run it without arguments, it will look in the available sources +to try to find a playing song and extract the lyrics.

            + +

            lrc artist song

            + +

            When you run it with arguments, it will use them to search for the +lyrics. This won't work if you manually disable the arguments source in +your configuration file.

            + +

            Commands

            + +

            The third way to use it is by passing it one of the following special +commands:

            + +
              +
            • lrc -l or lrc --list-sources lists the available sources.
            • +
            • lrc -e or lrc --enable SOURCE enable a source from the list.
            • +
            • lrc -d or lrc --disable SOURCE disable a source from the list.
            • +
            • lrc -r or lrc --reset SOURCE reset all configuration for a source.
            • +
            • lrc -v or lrc --version show the installed version of lyricli.
            • +
            • lrc -h or lrc --help display some help
            • +
            + +

            Roadmap

            + +

            There is not much defined right now as a roadmap, but this needs to be +done:

            + +
              +
            • Specs for all the components
            • +
            • YARD documentation for all the components
            • +
            + +

            And the first thing I want to work on after that is done is separating +the Lyrics Engines so we can add/remove lyrics engines in a similar way to how +we currently add/remove sources.

            + +

            Leave Feedback Please!

            + +

            If you decide to use or hack away at Lyricly, please don't forget to +post any issues you find.

            + +

            License

            + +

            Licensed under 3-clause-BSD.

            +
            + + + + + \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 87b6d5b..efaa475 100644 --- a/doc/index.html +++ b/doc/index.html @@ -134,7 +134,7 @@ post any issues you find.

            diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html index 9f9bf14..c618447 100644 --- a/doc/top-level-namespace.html +++ b/doc/top-level-namespace.html @@ -103,7 +103,7 @@ diff --git a/lib/lyricli/exceptions.rb b/lib/lyricli/exceptions.rb new file mode 100644 index 0000000..508c36b --- /dev/null +++ b/lib/lyricli/exceptions.rb @@ -0,0 +1,7 @@ +module Lyricli + # The namespace for all exceptions in Lyricli. Has no functionality by + # itself + module Exceptions + end +end + diff --git a/lib/lyricli/lyrics_engine.rb b/lib/lyricli/lyrics_engine.rb index 65e36db..beacd46 100644 --- a/lib/lyricli/lyrics_engine.rb +++ b/lib/lyricli/lyrics_engine.rb @@ -1,12 +1,21 @@ module Lyricli + + # This class gets the lyrics according to a given artist and song name. class LyricsEngine include Util + # Starts a new instance of LyricsEngine + # + # @param [String] artist the artist + # @param [String] song the song to look for def initialize(artist, song) @provider = URI("http://lyrics.wikia.com/api.php?artist=#{sanitize_param artist}&song=#{sanitize_param song}&fmt=realjson") end + # Asks Lyrics Wiki for the lyrics, also cleans up the output a little. + # + # @return [String] the lyrics def get_lyrics begin response = Net::HTTP.get(@provider) @@ -28,6 +37,5 @@ module Lyricli node.inner_text end - end end diff --git a/lib/lyricli/source_manager.rb b/lib/lyricli/source_manager.rb index 3befbd2..3514c34 100644 --- a/lib/lyricli/source_manager.rb +++ b/lib/lyricli/source_manager.rb @@ -1,8 +1,12 @@ module Lyricli + + # Manages the different sources. SourceManager is in charge of enabling and + # disabling them, as well as getting the current track. class SourceManager include Util + # Creates a new instance of SourceManager def initialize @enabled_sources = [] @config = Configuration.instance @@ -16,6 +20,11 @@ module Lyricli end end + # Enables a source. This runs the source's enable method and adds it to the + # `enabled_sources` configuration key. It will only enable sources that + # are "available" (see #available_sources) + # + # @param [String] source_name the name of the source to enable def enable(source_name) if available_sources.include?(source_name) if klass = parse_class(camelize(source_name)) @@ -31,6 +40,10 @@ module Lyricli end end + # Disables a source. This only removes the source from the `enabled_sources` + # configuration key. + # + # @param [String] source_name the name of the source to disable def disable(source_name) if available_sources.include?(source_name) if klass = parse_class(camelize(source_name)) @@ -44,6 +57,10 @@ module Lyricli end end + # Resets a source. This runs the source's reset method. It will also disable + # them. + # + # @param [String] source_name the name of the source to reset. def reset(source_name) if available_sources.include?(source_name) if klass = parse_class(camelize(source_name)) @@ -57,6 +74,9 @@ module Lyricli end end + # Iterates over every source to attempt to retrieve the current song. + # + # @return [Hash] the current track, has an `:artist` and `:song` key. def current_track track = nil lock = false @@ -78,24 +98,34 @@ module Lyricli track end + # Returns an array with the available sources. Optionally formats the result + # so active sources are identified by an appended * + # + # @param [Boolean] format whether or not to render the stars for active + # sources. + # @return [Array] the names of the currently available sources. def available_sources(format = false) path_root = File.expand_path(File.dirname(__FILE__)) sources = Dir[path_root+"/sources/*.rb"].map{ |s| name = s.split("/").last.gsub(/\.rb/, "") - - # Add a star to denote enabled sources name } # Remove arguments (Hack?) We don't want anybody to touch tihs one. sources.delete("arguments") if format + # Add a star to denote enabled sources format_sources(sources) else sources end end + # Adds a star to all members of the array that correspond to an active + # source + # + # @param [Array] sources the array of sources to format + # @return [Array] the formatted array def format_sources(sources) sources.map{ |s| s << "*" if @config["enabled_sources"].include?(s) diff --git a/lib/lyricli/sources.rb b/lib/lyricli/sources.rb new file mode 100644 index 0000000..459ce1c --- /dev/null +++ b/lib/lyricli/sources.rb @@ -0,0 +1,6 @@ +module Lyricli + # The namespace for all sources in Lyricli. Has no functionality by + # itself + module Sources + end +end diff --git a/lib/lyricli/sources/arguments.rb b/lib/lyricli/sources/arguments.rb index 82a8157..150c70a 100644 --- a/lib/lyricli/sources/arguments.rb +++ b/lib/lyricli/sources/arguments.rb @@ -1,5 +1,7 @@ module Lyricli module Sources + # The arguments source. This one is special since it expects two + # arguments. It is treated specially by the SourceManager. class Arguments class << self diff --git a/lib/lyricli/sources/itunes.rb b/lib/lyricli/sources/itunes.rb index 2e647c8..2bfe471 100644 --- a/lib/lyricli/sources/itunes.rb +++ b/lib/lyricli/sources/itunes.rb @@ -1,5 +1,6 @@ module Lyricli module Sources + # The source for iTunes class Itunes class << self diff --git a/lib/lyricli/sources/rdio.rb b/lib/lyricli/sources/rdio.rb index 40884b7..d34795f 100644 --- a/lib/lyricli/sources/rdio.rb +++ b/lib/lyricli/sources/rdio.rb @@ -1,5 +1,7 @@ module Lyricli module Sources + + # This is the Source for rdio class Rdio class << self @@ -32,6 +34,7 @@ module Lyricli # The current_track method should return the name of the current # artist and song. + # # @return [Hash] A hash containing the current `:song` and `:artist`. def current_track response = @rdio.call('currentUser', {'extras' => 'lastSongPlayed'})