Class: WTFChord::ComplexityCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/wtf_chord/complexity_counter.rb

Instance Method Summary collapse

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

#rateObject



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)
  barre = frets.uniq.keep_if { |o| frets.count(o) >= 2 }
  barre_strings = barre.min ? frets.count(barre.min).pred : 0

  base_rate = begin
    Rational(holded_strings - barre_strings, 4).to_f +
    Rational(finger_dist(@fingering.used_strings.map(&:fret)), 4).to_f
  end

  base_rate += 0.5 if (holded_strings - barre_strings) > 4

  # p [@fingering, holded_strings, barre_strings]

  if holded_strings > 4
    uniq_frets = frets.uniq.size

    if barre.size > 1 && uniq_frets == 3 && frets.count(barre.max) > barre_strings.next
      base_rate += 1 if complex_barre?(barre.max, frets)
    elsif barre_strings.next >= 2 || uniq_frets.size > 3
      base_rate += 1 if complex_barre?(barre.min, frets)
    end
  end

  base_rate + @fingering.extra_complexity
end