Class: WTFChord::ComplexityCounter
- Inherits:
-
Object
- Object
- WTFChord::ComplexityCounter
- Defined in:
- lib/wtf_chord/complexity_counter.rb
Instance Method Summary collapse
-
#initialize(fingering) ⇒ ComplexityCounter
constructor
A new instance of ComplexityCounter.
- #rate ⇒ Object
Constructor Details
#initialize(fingering) ⇒ ComplexityCounter
Returns a new instance of ComplexityCounter.
3 4 5 |
# File 'lib/wtf_chord/complexity_counter.rb', line 3 def initialize(fingering) @fingering = fingering end |
Instance Method Details
#rate ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wtf_chord/complexity_counter.rb', line 7 def rate frets = @fingering.holded_strings.map(&:fret) = frets.uniq.keep_if { |o| frets.count(o) >= 2 } = .min ? frets.count(.min).pred : 0 base_rate = begin Rational(holded_strings - , 4).to_f + Rational(finger_dist(@fingering.used_strings.map(&:fret)), 4).to_f end base_rate += 0.5 if (holded_strings - ) > 4 # p [@fingering, holded_strings, barre_strings] if holded_strings > 4 uniq_frets = frets.uniq.size if .size > 1 && uniq_frets == 3 && frets.count(.max) > .next base_rate += 1 if (.max, frets) elsif .next >= 2 || uniq_frets.size > 3 base_rate += 1 if (.min, frets) end end base_rate + @fingering.extra_complexity end |