Class: Sergovia::Scorers::Stretch

Inherits:
Object
  • Object
show all
Defined in:
lib/sergovia/scorers/stretch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fingering) ⇒ Stretch

Returns a new instance of Stretch.



7
8
9
# File 'lib/sergovia/scorers/stretch.rb', line 7

def initialize(fingering)
  @fingering = fingering
end

Instance Attribute Details

#fingeringObject (readonly)

Returns the value of attribute fingering.



5
6
7
# File 'lib/sergovia/scorers/stretch.rb', line 5

def fingering
  @fingering
end

Instance Method Details

#scoreObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sergovia/scorers/stretch.rb', line 11

def score
  #handle nils
  frets = fingering.notes.map(&:fret).reject { |n| n == 0 }.sort
  if frets.count > 1
    span = (frets.max - frets.min)
    if span > 6
      return 0.00
    elsif span == 6
      return 0.10
    elsif span == 5
      return 0.25
    elsif span == 4
      return 0.75
    else
      return 1.00
    end
  else
    return 1.00
  end
end