Class: WTFChord::Formatter
- Inherits:
-
Object
- Object
- WTFChord::Formatter
- Defined in:
- lib/wtf_chord/formatter.rb
Instance Method Summary collapse
- #call(*fingerings) ⇒ Object (also: #[])
- #formatter ⇒ Object
- #formatter? ⇒ Boolean
- #formatter_name ⇒ Object
-
#initialize(name, with_rates = false) ⇒ Formatter
constructor
A new instance of Formatter.
- #require_formatter! ⇒ Object
- #separator ⇒ Object
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 |
#formatter ⇒ Object
21 22 23 |
# File 'lib/wtf_chord/formatter.rb', line 21 def formatter Formatters.const_get(formatter_name) end |
#formatter? ⇒ Boolean
25 26 27 |
# File 'lib/wtf_chord/formatter.rb', line 25 def formatter? Formatters.const_defined?(formatter_name) end |
#formatter_name ⇒ Object
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 |
#separator ⇒ Object
17 18 19 |
# File 'lib/wtf_chord/formatter.rb', line 17 def separator formatter.separator end |