fretboard 1.5.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 032557dece35cf1703114d36c92d5c5cd24bff99f3b359423559503630dcd5f6
4
- data.tar.gz: 622a072b59c2d7f0e232e20032bd454651ffe89a25f5c0efb1686372c9416873
3
+ metadata.gz: 8fe73d0ec9fe65459863a1d69c89db528176f618484ade07d35b171662e337a2
4
+ data.tar.gz: 50a49bb50600ddeb7921d09188339a750a83657dcd453e051c2acab32ac5eb98
5
5
  SHA512:
6
- metadata.gz: 37ef216fad26e45060ac600273bc4a078fa677b13231b8aed014814c27bfbad5e15543136593823ab0e2262ee366ab958e982cefb0bfc88e8b3a8fa6294c3a71
7
- data.tar.gz: 5744d31b2ab94f6307d42e02362c40288744780cd1056fcc1837bbd1225205a8c3bf191beb1f7b88d36c4897d5c1941764a4f790b756fd2e3234c08af495d46a
6
+ metadata.gz: 01bdd0af72cb6b621dd6a9232397253f5aceed7aafd416863bdcf4e61a4d6505b0a4df6987f3000ed17e1c7e99a46fdbef3ff787d8288fce41fe2cef597957eb
7
+ data.tar.gz: fd464320449062acd34e8da6218297fa8787783b0812506980db6ce595291bd836f7514e31cef832831135c0de00d53ac118242cc3c1014b98e28c57eaef188b
data/README.md CHANGED
@@ -1,18 +1,40 @@
1
+ <div align="center">
2
+
1
3
  # Fretboard
2
4
 
3
5
  Tools for working with the guitar fretboard.
4
6
 
5
- [Documentation](https://www.rubydoc.info/gems/fretboard)
7
+ </div>
8
+
9
+ <div align="center">
10
+
11
+ [![Gem version](https://img.shields.io/gem/v/fretboard?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/fretboard)
12
+ [![Release Date](https://img.shields.io/github/release-date/afuno/fretboard)](https://github.com/afuno/fretboard/releases)
13
+ [![Downloads](https://img.shields.io/gem/dt/fretboard)](https://rubygems.org/gems/fretboard)
14
+ [![Ruby version](https://img.shields.io/badge/Ruby-3.2+-red)](https://github.com/afuno/fretboard)
15
+
16
+ </div>
17
+
18
+ ## 💡 Why Fretboard?
19
+
20
+ - 🎸 **27 Guitar Tunings** — Standard, Open, Drop, Modal and more
21
+ - 🎹 **Chromatic Notes** — Full sharp/flat notation support
22
+ - 📊 **Visual Fretboard** — ASCII table rendering in console
23
+ - ⚡ **CLI Tool** — Draw any tuning from the command line
24
+ - 🔧 **Ruby API** — Programmable fretboard data builder
25
+ - 🛤️ **Rails Ready** — Built-in Rails::Engine for integration
26
+
27
+ ## 🚀 Quick Start
6
28
 
7
- ## Installation
29
+ ### Installation
8
30
 
9
31
  ```ruby
10
32
  gem "fretboard"
11
33
  ```
12
34
 
13
- ## Using
35
+ ### Ruby API
14
36
 
15
- ### Creates a fretboard with the specified tuning
37
+ Creates a fretboard with the specified tuning:
16
38
 
17
39
  ```ruby
18
40
  fretboard = Fretboard::Builder.new(:standard)
@@ -20,7 +42,7 @@ fretboard = Fretboard::Builder.new(:standard)
20
42
  fretboard = Fretboard::Builder.standard
21
43
  ```
22
44
 
23
- [Supported guitar tunings](#supported-guitar-tunings)
45
+ [Supported guitar tunings](#-supported-guitar-tunings)
24
46
 
25
47
  Creating the fretboard data:
26
48
 
@@ -53,9 +75,9 @@ fretboard.draw
53
75
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
76
  ```
55
77
 
56
- ### Using from the console
78
+ ### CLI
57
79
 
58
- #### Drawing the fretboard
80
+ Drawing the fretboard:
59
81
 
60
82
  ```
61
83
  bundle exec fretboard --draw-tuning standard
@@ -78,10 +100,10 @@ bundle exec fretboard --draw-tuning standard
78
100
  ```
79
101
  </details>
80
102
 
81
- #### Getting a list of supported guitar tunings
103
+ Getting a list of supported guitar tunings:
82
104
 
83
105
  ```
84
- bundle exec fretboard --draw-tuning standard
106
+ bundle exec fretboard --tunings-list
85
107
  ```
86
108
 
87
109
  <details>
@@ -122,7 +144,39 @@ bundle exec fretboard --draw-tuning standard
122
144
  ```
123
145
  </details>
124
146
 
125
- ## Supported guitar tunings
147
+ ## 🎵 Supported Guitar Tunings
148
+
149
+ | Tuning | Notes |
150
+ |--------|-------|
151
+ | Standard | E, B, G, D, A, E |
152
+ | Tuning A | A, E, C, G, D, A |
153
+ | Open A | E, A, E, C#/Db, A, E |
154
+ | Drop A | B, F#/Gb, D, A, E, A |
155
+ | Drop A# | C, G, D#/Eb, A#/Bb, F, A#/Bb |
156
+ | Drop Ab | A#/Bb, F, C#/Db, G#/Ab, D#/Eb, G#/Ab |
157
+ | Tuning B | B, F#/Gb, D, A, E, B |
158
+ | Open B | D#/Eb, B, F#/Gb, B, F#/Gb, B |
159
+ | Drop B | C#/Db, G#/Ab, E, B, F#/Gb, B |
160
+ | Drop Bb | C, G, D#/Eb, A#/Bb, F, A#/Bb |
161
+ | Tuning C | C, G, D#/Eb, A#/Bb, F, C |
162
+ | Open C | E, C, G, C, G, C |
163
+ | Drop C | D, A, F, C, G, C |
164
+ | Tuning D | D, A, F, C, G, D |
165
+ | Open D | D, A, F#/Gb, D, A, D |
166
+ | Open D Minor | D, A, F, D, A, D |
167
+ | Drop D | E, B, G, D, A, D |
168
+ | Double Drop D | D, B, G, D, A, D |
169
+ | Modal D | D, A, G, D, A, D |
170
+ | Open E | E, B, G#/Ab, E, B, E |
171
+ | Tuning F | F, C, G#/Ab, D#/Eb, A#/Bb, F |
172
+ | Tuning G | G, D, A#/Bb, F, C, G |
173
+ | Open F | F, C, F, C, A, F |
174
+ | Open G | D, B, G, D, G, D |
175
+ | Open G Minor | D, A#/Bb, G, D, G, D |
176
+ | Drop G# | A#/Bb, F, C#/Db, G#/Ab, D#/Eb, G#/Ab |
177
+ | Modal G | D, C, G, D, G, D |
178
+
179
+ ### Fretboard Diagrams
126
180
 
127
181
  <details>
128
182
  <summary>Standard (standard)</summary>
@@ -146,7 +200,7 @@ bundle exec fretboard --draw-tuning standard
146
200
  </details>
147
201
 
148
202
  <details>
149
- <summary>A Tuning (tuning_a)</summary>
203
+ <summary>Tuning A (tuning_a)</summary>
150
204
 
151
205
  ```
152
206
  bundle exec fretboard --draw-tuning tuning_a
@@ -251,7 +305,7 @@ bundle exec fretboard --draw-tuning standard
251
305
  </details>
252
306
 
253
307
  <details>
254
- <summary>B Tuning (tuning_b)</summary>
308
+ <summary>Tuning B (tuning_b)</summary>
255
309
 
256
310
  ```
257
311
  bundle exec fretboard --draw-tuning tuning_b
@@ -335,7 +389,7 @@ bundle exec fretboard --draw-tuning standard
335
389
  </details>
336
390
 
337
391
  <details>
338
- <summary>C Tuning (tuning_c)</summary>
392
+ <summary>Tuning C (tuning_c)</summary>
339
393
 
340
394
  ```
341
395
  bundle exec fretboard --draw-tuning tuning_c
@@ -398,7 +452,7 @@ bundle exec fretboard --draw-tuning standard
398
452
  </details>
399
453
 
400
454
  <details>
401
- <summary>D Tuning (tuning_d)</summary>
455
+ <summary>Tuning D (tuning_d)</summary>
402
456
 
403
457
  ```
404
458
  bundle exec fretboard --draw-tuning tuning_d
@@ -545,7 +599,7 @@ bundle exec fretboard --draw-tuning standard
545
599
  </details>
546
600
 
547
601
  <details>
548
- <summary>F Tuning (tuning_f)</summary>
602
+ <summary>Tuning F (tuning_f)</summary>
549
603
 
550
604
  ```
551
605
  bundle exec fretboard --draw-tuning tuning_f
@@ -565,6 +619,27 @@ bundle exec fretboard --draw-tuning standard
565
619
  ```
566
620
  </details>
567
621
 
622
+ <details>
623
+ <summary>Tuning G (tuning_g)</summary>
624
+
625
+ ```
626
+ bundle exec fretboard --draw-tuning tuning_g
627
+ ```
628
+
629
+ ```
630
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
631
+ | № | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
632
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
633
+ | 1 | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G |
634
+ | 2 | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D |
635
+ | 3 | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb |
636
+ | 4 | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F |
637
+ | 5 | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C |
638
+ | 6 | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G |
639
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
640
+ ```
641
+ </details>
642
+
568
643
  <details>
569
644
  <summary>Open F (open_f)</summary>
570
645
 
@@ -586,27 +661,6 @@ bundle exec fretboard --draw-tuning standard
586
661
  ```
587
662
  </details>
588
663
 
589
- <details>
590
- <summary>G Tuning (tuning_g)</summary>
591
-
592
- ```
593
- bundle exec fretboard --draw-tuning tuning_g
594
- ```
595
-
596
- ```
597
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
598
- | № | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
599
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
600
- | 1 | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G |
601
- | 2 | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D |
602
- | 3 | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb |
603
- | 4 | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F |
604
- | 5 | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G | G#/Ab | A | A#/Bb | B | C |
605
- | 6 | G | G#/Ab | A | A#/Bb | B | C | C#/Db | D | D#/Eb | E | F | F#/Gb | G |
606
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
607
- ```
608
- </details>
609
-
610
664
  <details>
611
665
  <summary>Open G (open_g)</summary>
612
666
 
@@ -690,3 +744,23 @@ bundle exec fretboard --draw-tuning standard
690
744
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691
745
  ```
692
746
  </details>
747
+
748
+ ## 🤝 Contributing
749
+
750
+ We welcome contributions! Here are some ways you can help:
751
+
752
+ - 🐛 Report bugs and issues
753
+ - 💡 Suggest new features
754
+ - 📝 Improve documentation
755
+ - 🧪 Add test cases
756
+ - 🔧 Submit pull requests
757
+
758
+ Please read our [Contributing Guide](./CONTRIBUTING.md) before submitting a pull request.
759
+
760
+ ## 🙏 Acknowledgments
761
+
762
+ Thank you to all [contributors](https://github.com/afuno/fretboard/graphs/contributors) who have helped make Fretboard better!
763
+
764
+ ## 📄 License
765
+
766
+ Fretboard is available as open source under the terms of the [MIT License](./LICENSE.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/fretboard CHANGED
@@ -1,19 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- abort "Please run fretboard from the root of the project" unless File.exist?("./Gemfile")
5
-
6
- require "rubygems"
7
-
8
- begin
9
- require "bundler"
10
- Bundler.setup
11
- rescue StandardError
12
- # ...
13
- end
14
-
15
- $LOAD_PATH << "#{__dir__}/../lib"
16
-
17
- require "fretboard/parser"
4
+ require "fretboard"
18
5
 
19
6
  Fretboard::Parser.parse(ARGV)
@@ -1,190 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require 'active_support/core_ext/hash'
4
-
5
- require "fretboard/console"
6
-
7
3
  module Fretboard
8
- class Builder # rubocop:disable Metrics/ClassLength
9
- # fretboard = Fretboard::Builder.new(:standard)
10
- # fretboard = Fretboard::Builder.standard
11
- # fretboard = Fretboard::Builder.tuning_a
12
- # fretboard = Fretboard::Builder.open_a
13
- # fretboard = Fretboard::Builder.drop_a
14
- # fretboard = Fretboard::Builder.drop_a_sharp
15
- # fretboard = Fretboard::Builder.drop_a_flat
16
- # fretboard = Fretboard::Builder.tuning_b
17
- # fretboard = Fretboard::Builder.open_b
18
- # fretboard = Fretboard::Builder.drop_b
19
- # fretboard = Fretboard::Builder.drop_b_flat
20
- # fretboard = Fretboard::Builder.tuning_c
21
- # fretboard = Fretboard::Builder.open_c
22
- # fretboard = Fretboard::Builder.drop_c
23
- # fretboard = Fretboard::Builder.tuning_d
24
- # fretboard = Fretboard::Builder.open_d
25
- # fretboard = Fretboard::Builder.open_d_minor
26
- # fretboard = Fretboard::Builder.drop_d
27
- # fretboard = Fretboard::Builder.double_drop_d
28
- # fretboard = Fretboard::Builder.modal_d
29
- # fretboard = Fretboard::Builder.open_e
30
- # fretboard = Fretboard::Builder.tuning_f
31
- # fretboard = Fretboard::Builder.open_f
32
- # fretboard = Fretboard::Builder.tuning_g
33
- # fretboard = Fretboard::Builder.open_g
34
- # fretboard = Fretboard::Builder.open_g_minor
35
- # fretboard = Fretboard::Builder.drop_g_sharp
36
- # fretboard = Fretboard::Builder.modal_g
37
-
38
- # fretboard.build
39
- # fretboard.data
40
- # fretboard.draw
41
-
4
+ class Builder
42
5
  DEFAULT_NUMBER_OF_FRETS = 12
43
6
 
44
- # METHODS_NAMES = %i[
45
- # standard
46
- # tuning_a
47
- # open_a
48
- # drop_a
49
- # drop_a_sharp
50
- # drop_a_flat
51
- # tuning_b
52
- # open_b
53
- # drop_b
54
- # drop_b_flat
55
- # tuning_c
56
- # open_c
57
- # drop_c
58
- # tuning_d
59
- # open_d
60
- # open_d_minor
61
- # drop_d
62
- # double_drop_d
63
- # modal_d
64
- # open_e
65
- # tuning_f
66
- # open_f
67
- # tuning_g
68
- # open_g
69
- # open_g_minor
70
- # drop_g_sharp
71
- # modal_g
72
- # ].freeze
73
-
74
7
  attr_reader :data
75
8
 
76
- # METHODS_NAMES.each do |method_name|
77
- # define_method(method_name) do |number_of_frets = DEFAULT_NUMBER_OF_FRETS|
78
- # new(method_name, number_of_frets)
79
- # end
80
- # end
81
-
82
- def self.standard(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
83
- new(:standard, number_of_frets)
84
- end
85
-
86
- def self.tuning_a(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
87
- new(:tuning_a, number_of_frets)
88
- end
89
-
90
- def self.open_a(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
91
- new(:open_a, number_of_frets)
92
- end
93
-
94
- def self.drop_a(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
95
- new(:drop_a, number_of_frets)
96
- end
97
-
98
- def self.drop_a_sharp(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
99
- new(:drop_a_sharp, number_of_frets)
100
- end
101
-
102
- def self.drop_a_flat(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
103
- new(:drop_a_flat, number_of_frets)
104
- end
105
-
106
- def self.tuning_b(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
107
- new(:tuning_b, number_of_frets)
108
- end
109
-
110
- def self.open_b(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
111
- new(:open_b, number_of_frets)
112
- end
113
-
114
- def self.drop_b(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
115
- new(:drop_b, number_of_frets)
116
- end
117
-
118
- def self.drop_b_flat(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
119
- new(:drop_b_flat, number_of_frets)
120
- end
121
-
122
- def self.tuning_c(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
123
- new(:tuning_c, number_of_frets)
124
- end
125
-
126
- def self.open_c(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
127
- new(:open_c, number_of_frets)
128
- end
129
-
130
- def self.drop_c(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
131
- new(:drop_c, number_of_frets)
132
- end
133
-
134
- def self.tuning_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
135
- new(:tuning_d, number_of_frets)
136
- end
137
-
138
- def self.open_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
139
- new(:open_d, number_of_frets)
140
- end
141
-
142
- def self.open_d_minor(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
143
- new(:open_d_minor, number_of_frets)
144
- end
145
-
146
- def self.drop_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
147
- new(:drop_d, number_of_frets)
148
- end
149
-
150
- def self.double_drop_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
151
- new(:double_drop_d, number_of_frets)
152
- end
153
-
154
- def self.modal_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
155
- new(:modal_d, number_of_frets)
156
- end
157
-
158
- def self.open_e(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
159
- new(:open_e, number_of_frets)
160
- end
161
-
162
- def self.tuning_f(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
163
- new(:tuning_f, number_of_frets)
164
- end
165
-
166
- def self.open_f(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
167
- new(:open_f, number_of_frets)
168
- end
169
-
170
- def self.tuning_g(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
171
- new(:tuning_g, number_of_frets)
172
- end
173
-
174
- def self.open_g(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
175
- new(:open_g, number_of_frets)
176
- end
177
-
178
- def self.open_g_minor(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
179
- new(:open_g_minor, number_of_frets)
180
- end
181
-
182
- def self.drop_g_sharp(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
183
- new(:drop_g_sharp, number_of_frets)
184
- end
185
-
186
- def self.modal_g(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
187
- new(:modal_g, number_of_frets)
9
+ Fretboard::Tunings.list.each_key do |tuning_name|
10
+ define_singleton_method(tuning_name.downcase) do |number_of_frets = DEFAULT_NUMBER_OF_FRETS|
11
+ new(tuning_name, number_of_frets)
12
+ end
188
13
  end
189
14
 
190
15
  def initialize(tuning, number_of_frets = DEFAULT_NUMBER_OF_FRETS)
@@ -195,51 +20,37 @@ module Fretboard
195
20
  end
196
21
 
197
22
  def build(sharp_or_flat: :both) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
198
- unless Fretboard::Tunings.exists?(@tuning)
199
- Fretboard::Console.danger("Unable to detect guitar tuning")
200
- return
201
- end
23
+ raise Fretboard::Exceptions::UnknownTuning, @tuning unless Fretboard::Tunings.exists?(@tuning)
24
+
25
+ @sharp_or_flat = sharp_or_flat
202
26
 
203
27
  tuning = Fretboard::Tunings.fetch(@tuning)
204
28
  strings = tuning[:STRINGS]
205
29
  number_of_strings = strings.size
206
30
 
207
31
  (1..number_of_strings).each do |string_number|
208
- # puts
209
- # puts "String: #{string_number}"
210
- # puts
211
-
212
32
  current_note = strings[string_number][:NOTE]
213
33
 
214
34
  @data[string_number] = {}
215
-
216
- # puts "Fret: 0 (#{current_note})"
217
-
218
35
  @data[string_number][0] = current_note
219
36
 
220
37
  (1..@number_of_frets).each do |fret|
221
38
  next_note = Fretboard::Note.next_for(
222
39
  current_note,
223
- sharp_or_flat: sharp_or_flat
40
+ sharp_or_flat:
224
41
  )
225
42
 
226
- # puts "Fret: #{fret} (#{next_note})"
227
-
228
43
  @data[string_number][fret] = next_note
229
44
 
230
45
  current_note = next_note
231
46
  end
232
47
  end
233
48
 
234
- # puts
235
- # puts 'done'
49
+ self
236
50
  end
237
51
 
238
- def draw(sharp_or_flat: :both) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
239
- unless @data.any?
240
- Fretboard::Console.danger("Build the guitar fretboard data for drawing")
241
- return
242
- end
52
+ def draw(sharp_or_flat: @sharp_or_flat || :both) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
53
+ raise Fretboard::Exceptions::NotBuilt unless @data.any?
243
54
 
244
55
  headings = []
245
56
  rows = []
@@ -252,18 +63,7 @@ module Fretboard
252
63
 
253
64
  headings << 0
254
65
 
255
- open_note = string_notes[0]
256
-
257
- if open_note.is_a?(Array)
258
- open_note = case sharp_or_flat
259
- when :both
260
- open_note.join("/")
261
- when :sharp
262
- open_note.first
263
- else
264
- open_note.last
265
- end
266
- end
66
+ open_note = Fretboard::NoteFormatter.format(string_notes[0], sharp_or_flat:)
267
67
 
268
68
  row << open_note
269
69
 
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "colorize"
4
- require "terminal-table"
5
-
6
3
  module Fretboard
7
4
  class Console
8
5
  def self.log(text)
@@ -23,8 +20,8 @@ module Fretboard
23
20
 
24
21
  def self.print_table(headings, rows)
25
22
  table = Terminal::Table.new(
26
- headings: headings,
27
- rows: rows,
23
+ headings:,
24
+ rows:,
28
25
  style: { border_x: "~", border_i: "~" }
29
26
  )
30
27
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ class Engine < Rails::Engine
5
+ isolate_namespace Fretboard
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ module Exceptions
5
+ class Base < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ module Exceptions
5
+ class NotBuilt < Base
6
+ def initialize(msg = nil)
7
+ super(msg || "Build the guitar fretboard data for drawing")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ module Exceptions
5
+ class UnknownNote < Base
6
+ def initialize(note = nil)
7
+ message = "Unknown note"
8
+ message = "#{message}: #{note}" if note
9
+ super(message)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ module Exceptions
5
+ class UnknownTuning < Base
6
+ def initialize(tuning_name = nil)
7
+ message = "Unable to detect guitar tuning"
8
+ message = "#{message}: #{tuning_name}" if tuning_name
9
+ super(message)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,38 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fretboard/notes"
4
-
5
3
  module Fretboard
6
4
  class Note
7
- # Fretboard::Note.next_for('C')
8
- # Fretboard::Note.next_for(['F#', 'Gb'])
9
- # Fretboard::Note.next_for('F#/Gb')
10
-
11
- def self.next_for(note, sharp_or_flat: :both) # rubocop:disable Metrics/MethodLength
5
+ def self.next_for(note, sharp_or_flat: :both)
12
6
  all_notes = Fretboard::Notes.all(sharp_or_flat)
13
7
 
14
- if note.is_a?(Array)
15
- note = case sharp_or_flat
16
- when :both
17
- note.join("/")
18
- when :sharp
19
- note.first
20
- else
21
- note.last
22
- end
23
- end
8
+ note = Fretboard::NoteFormatter.format(note, sharp_or_flat:)
24
9
 
25
10
  current_index = all_notes.find_index(note)
11
+ raise Fretboard::Exceptions::UnknownNote, note if current_index.nil?
12
+
26
13
  next_index = current_index + 1
27
14
 
28
15
  next_note = all_notes[next_index]
29
- next_note = all_notes.first if next_note.blank?
16
+ next_note = all_notes.first if next_note.nil?
30
17
 
31
18
  next_note
32
19
  end
33
-
34
- def initialize(note)
35
- @note = note
36
- end
37
20
  end
38
21
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fretboard
4
+ module NoteFormatter
5
+ def self.format(note, sharp_or_flat: :both)
6
+ return note unless note.is_a?(Array)
7
+
8
+ case sharp_or_flat
9
+ when :both then note.join("/")
10
+ when :sharp then note.first
11
+ else note.last
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,10 +2,6 @@
2
2
 
3
3
  module Fretboard
4
4
  class Notes
5
- # Fretboard::Notes.all(:both)
6
- # Fretboard::Notes.all(:sharp)
7
- # Fretboard::Notes.all(:flat)
8
-
9
5
  BASIC_NOTES = {
10
6
  1 => "C",
11
7
  2 => %w[C# Db],
@@ -21,22 +17,9 @@ module Fretboard
21
17
  12 => "B"
22
18
  }.freeze
23
19
 
24
- def self.all(sharp_or_flat = :sharp) # rubocop:disable Metrics/MethodLength
20
+ def self.all(sharp_or_flat = :sharp)
25
21
  BASIC_NOTES.map do |_key, value|
26
- result = value
27
-
28
- if value.is_a?(Array)
29
- result = case sharp_or_flat
30
- when :both
31
- value.join("/")
32
- when :sharp
33
- value.first
34
- else
35
- value.last
36
- end
37
- end
38
-
39
- result
22
+ Fretboard::NoteFormatter.format(value, sharp_or_flat:)
40
23
  end
41
24
  end
42
25
 
@@ -1,13 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/object/blank"
4
- require "optparse"
5
-
6
- require "fretboard/builder"
7
- require "fretboard/console"
8
- require "fretboard/note"
9
- require "fretboard/tunings"
10
-
11
3
  module Fretboard
12
4
  class Parser
13
5
  attr_reader :args
@@ -22,8 +14,10 @@ module Fretboard
22
14
 
23
15
  def parse
24
16
  parser.parse!(args)
17
+ rescue Fretboard::Exceptions::Base, OptionParser::ParseError => e
18
+ Fretboard::Console.danger(e.message)
25
19
  rescue StandardError => e
26
- Fretboard::Console.danger("Ambiguously completable string is encountered\n#{e}")
20
+ Fretboard::Console.danger("Unexpected error: #{e.message}")
27
21
  end
28
22
 
29
23
  private
@@ -33,7 +27,7 @@ module Fretboard
33
27
  opts.banner = "Usage: fretboard [options]"
34
28
 
35
29
  opts.on("-v", "--version", "The current version of the gem") do
36
- Fretboard::Console.log(Fretboard::VERSION)
30
+ Fretboard::Console.log(Fretboard::VERSION::STRING)
37
31
  exit
38
32
  end
39
33
 
@@ -31,9 +31,9 @@ module Fretboard
31
31
  OPEN_A: {
32
32
  STRINGS: {
33
33
  1 => { NOTE: "E" },
34
- 2 => { NOTE: "A" },
35
- 3 => { NOTE: "E" },
36
- 4 => { NOTE: %w[C# Db] },
34
+ 2 => { NOTE: %w[C# Db] },
35
+ 3 => { NOTE: "A" },
36
+ 4 => { NOTE: "E" },
37
37
  5 => { NOTE: "A" },
38
38
  6 => { NOTE: "E" }
39
39
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Fretboard
4
4
  module VERSION
5
- MAJOR = 1
6
- MINOR = 5
7
- PATCH = 1
5
+ MAJOR = 2
6
+ MINOR = 0
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
data/lib/fretboard.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fretboard/builder"
4
- # require 'fretboard/constants'
5
- require "fretboard/note"
6
- require "fretboard/notes"
7
- require "fretboard/tunings"
8
-
9
- module Fretboard
10
- # extend Constants
11
- end
3
+ require "zeitwerk"
4
+
5
+ require "colorize"
6
+ require "optparse"
7
+ require "terminal-table"
8
+
9
+ loader = Zeitwerk::Loader.for_gem
10
+ loader.setup
11
+
12
+ module Fretboard; end
13
+
14
+ require "fretboard/engine" if defined?(Rails::Engine)
metadata CHANGED
@@ -1,85 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fretboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-06-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: activesupport
13
+ name: colorize
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '7.0'
18
+ version: '0.8'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '7.0'
25
+ version: '0.8'
27
26
  - !ruby/object:Gem::Dependency
28
- name: colorize
27
+ name: terminal-table
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '0.8'
32
+ version: '4.0'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '0.8'
39
+ version: '4.0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: terminal-table
41
+ name: zeitwerk
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "~>"
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: '3.0'
46
+ version: '2.6'
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - "~>"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
53
66
  - !ruby/object:Gem::Version
54
- version: '3.0'
67
+ version: '13.0'
55
68
  - !ruby/object:Gem::Dependency
56
- name: rubocop
69
+ name: rspec
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
- - - "~>"
72
+ - - ">="
60
73
  - !ruby/object:Gem::Version
61
- version: '1.50'
74
+ version: '3.12'
62
75
  type: :development
63
76
  prerelease: false
64
77
  version_requirements: !ruby/object:Gem::Requirement
65
78
  requirements:
66
- - - "~>"
79
+ - - ">="
67
80
  - !ruby/object:Gem::Version
68
- version: '1.50'
81
+ version: '3.12'
69
82
  - !ruby/object:Gem::Dependency
70
- name: rubocop-performance
83
+ name: servactory-rubocop
71
84
  requirement: !ruby/object:Gem::Requirement
72
85
  requirements:
73
- - - "~>"
86
+ - - ">="
74
87
  - !ruby/object:Gem::Version
75
- version: '1.17'
88
+ version: '0.9'
76
89
  type: :development
77
90
  prerelease: false
78
91
  version_requirements: !ruby/object:Gem::Requirement
79
92
  requirements:
80
- - - "~>"
93
+ - - ">="
81
94
  - !ruby/object:Gem::Version
82
- version: '1.17'
95
+ version: '0.9'
83
96
  description: Tools for working with the guitar fretboard
84
97
  email:
85
98
  - profox.rus@gmail.com
@@ -89,12 +102,18 @@ extensions: []
89
102
  extra_rdoc_files: []
90
103
  files:
91
104
  - README.md
105
+ - Rakefile
92
106
  - bin/fretboard
93
107
  - lib/fretboard.rb
94
108
  - lib/fretboard/builder.rb
95
109
  - lib/fretboard/console.rb
96
- - lib/fretboard/constants.rb
110
+ - lib/fretboard/engine.rb
111
+ - lib/fretboard/exceptions/base.rb
112
+ - lib/fretboard/exceptions/not_built.rb
113
+ - lib/fretboard/exceptions/unknown_note.rb
114
+ - lib/fretboard/exceptions/unknown_tuning.rb
97
115
  - lib/fretboard/note.rb
116
+ - lib/fretboard/note_formatter.rb
98
117
  - lib/fretboard/notes.rb
99
118
  - lib/fretboard/parser.rb
100
119
  - lib/fretboard/tunings.rb
@@ -108,7 +127,6 @@ metadata:
108
127
  source_code_uri: https://github.com/afuno/fretboard
109
128
  bug_tracker_uri: https://github.com/afuno/fretboard/issues
110
129
  rubygems_mfa_required: 'true'
111
- post_install_message:
112
130
  rdoc_options: []
113
131
  require_paths:
114
132
  - lib
@@ -116,15 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
134
  requirements:
117
135
  - - ">="
118
136
  - !ruby/object:Gem::Version
119
- version: 2.7.0
137
+ version: '3.2'
120
138
  required_rubygems_version: !ruby/object:Gem::Requirement
121
139
  requirements:
122
140
  - - ">="
123
141
  - !ruby/object:Gem::Version
124
142
  version: '0'
125
143
  requirements: []
126
- rubygems_version: 3.3.7
127
- signing_key:
144
+ rubygems_version: 4.0.6
128
145
  specification_version: 4
129
146
  summary: Tools for working with the guitar fretboard
130
147
  test_files: []
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # module Fretboard
4
- # module Constants
5
- # # Fretboard::Constants.constants
6
- # end
7
- # end