Class: Homophone::Formatter::ConsoleFormatter

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ConsoleFormatter

Returns a new instance of ConsoleFormatter.



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

def initialize(opts = {})
  @show_genre = !!opts[:show_genre]
end

Instance Method Details

#format(artist) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/homophone/formatter.rb', line 8

def format(artist)
  if show_genre?
    "#{artist.name} (#{artist.genres.join(', ')})".sub(/ \(\)/, '')
  else
    artist.name
  end
end

#show_genre?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/homophone/formatter.rb', line 16

def show_genre?
  @show_genre
end