Class: Chords::TextFormatter
- Inherits:
-
Object
- Object
- Chords::TextFormatter
- Defined in:
- lib/chords/text_formatter.rb
Instance Method Summary collapse
-
#initialize(fretboard) ⇒ TextFormatter
constructor
A new instance of TextFormatter.
- #print(title, fingerings, opts = {}) ⇒ Object
Constructor Details
#initialize(fretboard) ⇒ TextFormatter
Returns a new instance of TextFormatter.
6 7 8 |
# File 'lib/chords/text_formatter.rb', line 6 def initialize(fretboard) @fretboard = fretboard end |
Instance Method Details
#print(title, fingerings, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chords/text_formatter.rb', line 10 def print(title, fingerings, opts={}) rows = [""] * @fretboard.open_notes.size fingerings.each do |fingering| fingering.each_with_index do |position,i| rows[i] += "-#{position ? position.to_s.rjust(2,'-') : '-X'}--" end end idx = 0 output = '' while rows.first.length > idx parts = [] rows.each_with_index do |row, i| parts << "#{@fretboard.open_notes[i].title.rjust(2, ' ')}: " + row[idx...(idx+75)] end output += "\n" + (parts.reverse.join("\n")) + "\n\n" idx += 75 end output += "Total #{fingerings.size} fingerings." if opts[:inline] output else puts output end end |