Class: WTFChord::Formatter

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

Instance Method Summary collapse

Constructor Details

#initialize(name, with_rates = false) ⇒ Formatter

Returns a new instance of Formatter.



5
6
7
8
9
# File 'lib/wtf_chord/formatter.rb', line 5

def initialize(name, with_rates = false)
  @name = name
  @with_rates = with_rates
  require_formatter! unless formatter?
end

Instance Method Details

#call(*fingerings) ⇒ Object Also known as: []



11
12
13
# File 'lib/wtf_chord/formatter.rb', line 11

def call(*fingerings)
  formatter.with_rates(@with_rates) { |f| fingerings.map(&f) }
end

#formatterObject



21
22
23
# File 'lib/wtf_chord/formatter.rb', line 21

def formatter
  Formatters.const_get(formatter_name)
end

#formatter?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/wtf_chord/formatter.rb', line 25

def formatter?
  Formatters.const_defined?(formatter_name)
end

#formatter_nameObject



29
30
31
# File 'lib/wtf_chord/formatter.rb', line 29

def formatter_name
  @formatter_name ||= @name.gsub(/(?:^|_)([a-z\d]*)/i) { "#{$1.capitalize}" }.to_s.freeze
end

#require_formatter!Object



33
34
35
# File 'lib/wtf_chord/formatter.rb', line 33

def require_formatter!
  require "wtf_chord/formatters/#{@name}"
end

#separatorObject



17
18
19
# File 'lib/wtf_chord/formatter.rb', line 17

def separator
  formatter.separator
end