Class: Homophone::Application
- Inherits:
-
Object
- Object
- Homophone::Application
- Defined in:
- lib/homophone/application.rb
Instance Method Summary collapse
- #formatter ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #ohai(msg) ⇒ Object
- #onoe(exit_code, msg) ⇒ Object
- #run(argv) ⇒ Object
- #show_genre? ⇒ Boolean
- #spotify_service ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
12 13 14 |
# File 'lib/homophone/application.rb', line 12 def initialize @show_genre = false end |
Instance Method Details
#formatter ⇒ Object
57 58 59 60 |
# File 'lib/homophone/application.rb', line 57 def formatter opts = {:show_genre => show_genre?} @formatter ||= Homophone::Formatter::ConsoleFormatter.new(opts) end |
#ohai(msg) ⇒ Object
62 63 64 65 |
# File 'lib/homophone/application.rb', line 62 def ohai(msg) puts msg exit 0 end |
#onoe(exit_code, msg) ⇒ Object
67 68 69 70 |
# File 'lib/homophone/application.rb', line 67 def onoe(exit_code, msg) STDERR.puts msg exit exit_code end |
#run(argv) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/homophone/application.rb', line 16 def run(argv) opts = Slop.parse do |o| o. = 'Usage: homophone [-g] ARTIST' o.separator '' o.separator 'Options:' o.bool '-g', '--genre', 'Show artist genres' o.on '-h', '--help' do ohai o end o.on '--version' do ohai "homophone v#{Homophone::VERSION}" end end musician_name = opts.arguments.shift onoe 127, 'No musician name provided' unless musician_name @show_genre = opts.genre? musician = spotify_service.musician(musician_name) onoe 126, %Q{No musician with name "#{musician_name}" found} if musician.nil? puts "#{formatter.format(musician)}:\n\n" if show_genre? artists = musician..sort_by(&:name) artists.each do |artist| puts formatter.format(artist) end end |
#show_genre? ⇒ Boolean
53 54 55 |
# File 'lib/homophone/application.rb', line 53 def show_genre? !!@show_genre end |