Class: WTFChord::Formatter
- Inherits:
-
Object
- Object
- WTFChord::Formatter
- Defined in:
- lib/wtf_chord/formatter.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
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.
7 8 9 10 11 |
# File 'lib/wtf_chord/formatter.rb', line 7 def initialize(name, with_rates = false) @name = name @with_rates = with_rates require_formatter! unless formatter? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/wtf_chord/formatter.rb', line 5 def name @name end |
Instance Method Details
#call(*fingerings) ⇒ Object Also known as: []
13 14 15 |
# File 'lib/wtf_chord/formatter.rb', line 13 def call(*fingerings) formatter.with_rates(@with_rates) { |f| fingerings.map(&f) } end |
#formatter ⇒ Object
23 24 25 |
# File 'lib/wtf_chord/formatter.rb', line 23 def formatter Formatters.const_get(formatter_name) end |
#formatter? ⇒ Boolean
27 28 29 |
# File 'lib/wtf_chord/formatter.rb', line 27 def formatter? Formatters.const_defined?(formatter_name) end |
#formatter_name ⇒ Object
31 32 33 |
# File 'lib/wtf_chord/formatter.rb', line 31 def formatter_name @formatter_name ||= @name.gsub(/(?:^|_)([a-z\d]*)/i) { "#{$1.capitalize}" }.to_s.freeze end |
#require_formatter! ⇒ Object
35 36 37 |
# File 'lib/wtf_chord/formatter.rb', line 35 def require_formatter! require "wtf_chord/formatters/#{@name}" end |
#separator ⇒ Object
19 20 21 |
# File 'lib/wtf_chord/formatter.rb', line 19 def separator formatter.separator end |