Class: Homophone::Formatter::ConsoleFormatter
- Inherits:
-
Object
- Object
- Homophone::Formatter::ConsoleFormatter
- Defined in:
- lib/homophone/formatter.rb
Instance Method Summary collapse
- #format(artist) ⇒ Object
-
#initialize(opts = {}) ⇒ ConsoleFormatter
constructor
A new instance of ConsoleFormatter.
- #show_genre? ⇒ Boolean
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
16 17 18 |
# File 'lib/homophone/formatter.rb', line 16 def show_genre? @show_genre end |