class Homophone::Application

Public Class Methods

new() click to toggle source
# File lib/homophone/application.rb, line 12
def initialize
  @show_genre = false
end

Public Instance Methods

formatter() click to toggle source
# File lib/homophone/application.rb, line 57
def formatter
  opts = {:show_genre => show_genre?}
  @formatter ||= Homophone::Formatter::ConsoleFormatter.new(opts)
end
ohai(msg) click to toggle source
# File lib/homophone/application.rb, line 62
def ohai(msg)
  puts msg
  exit 0
end
onoe(exit_code, msg) click to toggle source
# File lib/homophone/application.rb, line 67
def onoe(exit_code, msg)
  STDERR.puts msg
  exit exit_code
end
run(argv) click to toggle source
# File lib/homophone/application.rb, line 16
def run(argv)
  opts = Slop.parse do |o|
    o.banner = '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.related_artists.sort_by(&:name)
  artists.each do |artist|
    puts formatter.format(artist)
  end
end
show_genre?() click to toggle source
# File lib/homophone/application.rb, line 53
def show_genre?
  !!@show_genre
end
spotify_service() click to toggle source
# File lib/homophone/application.rb, line 49
def spotify_service
  @service ||= (cucumber? ? Homophone::Service::DummySpotify : Homophone::Service::Spotify).new
end

Private Instance Methods

cucumber?() click to toggle source
# File lib/homophone/application.rb, line 74
def cucumber?
  ENV['HOMOPHONE_ENV'] == 'cucumber'
end