Class: Fretboard::Builder
- Inherits:
-
Object
- Object
- Fretboard::Builder
- Defined in:
- lib/fretboard/builder.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
fretboard = Fretboard::Builder.new(:standart) fretboard = Fretboard::Builder.standart fretboard.build fretboard.data fretboard.draw.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #draw ⇒ Object
-
#initialize(tuning, number_of_frets = 12) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(tuning, number_of_frets = 12) ⇒ Builder
17 18 19 20 21 22 |
# File 'lib/fretboard/builder.rb', line 17 def initialize(tuning, number_of_frets = 12) @tuning = tuning.upcase.to_sym @number_of_frets = number_of_frets @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
fretboard = Fretboard::Builder.new(:standart) fretboard = Fretboard::Builder.standart fretboard.build fretboard.data fretboard.draw
11 12 13 |
# File 'lib/fretboard/builder.rb', line 11 def data @data end |
Class Method Details
.standart(number_of_frets = 12) ⇒ Object
13 14 15 |
# File 'lib/fretboard/builder.rb', line 13 def self.standart(number_of_frets = 12) new(:standart, number_of_frets) end |
Instance Method Details
#build ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fretboard/builder.rb', line 24 def build unless Fretboard::Constants::GUITAR_TUNINGS.key?(@tuning) puts 'Unable to detect guitar tuning' return end tuning = Fretboard::Constants::GUITAR_TUNINGS[@tuning] strings = tuning[:STRINGS] number_of_strings = strings.size (1..number_of_strings).each do |string_number| puts puts "String: #{string_number}" puts current_note = strings[string_number][:NOTE] @data[string_number] = {} puts "Fret: 0 (#{current_note})" @data[string_number][0] = current_note (1..@number_of_frets).each do |fret| next_note = Fretboard::Note.next_for( current_note, sharp_or_flat: :both, formated: true ) puts "Fret: #{fret} (#{next_note})" @data[string_number][fret] = next_note current_note = next_note end end puts puts 'done' end |
#draw ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fretboard/builder.rb', line 66 def draw headings = [] rows = [] @data.each_pair do |string_number, string_notes| row = [] headings << '№' row << string_number headings << 0 row << string_notes[0] string_notes.except(0).each_pair do |fret, note| headings << fret row << note end rows << row end table = Terminal::Table.new( headings: headings.uniq, rows: rows, style: { border_x: '~', border_i: '~' } ) puts table nil end |