Class: WTFChord::Fingering

Inherits:
Fretboard show all
Defined in:
lib/wtf_chord/fingering.rb

Constant Summary

Constants inherited from Fretboard

WTFChord::Fretboard::DEAD

Instance Attribute Summary

Attributes inherited from Fretboard

#capo, #strings

Instance Method Summary collapse

Methods inherited from Fretboard

#[], #fingers, #set_capo, #to_s, #with_capo

Constructor Details

#initialize(guitar, fingers = nil) {|_self| ... } ⇒ Fingering

Returns a new instance of Fingering.

Yields:

  • (_self)

Yield Parameters:



7
8
9
10
11
12
# File 'lib/wtf_chord/fingering.rb', line 7

def initialize(guitar, fingers = nil)
  @capo      = guitar.capo
  @strings   = guitar.strings.map(&:dup)
  set_fingers(fingers) if fingers.is_a?(Array)
  yield(self) if block_given?
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/wtf_chord/fingering.rb', line 18

def == other
  case other
  when Fingering then other.code == code
  when Array     then other == @strings.map(&:fret)
  else super
  end
end

#codeObject



14
15
16
# File 'lib/wtf_chord/fingering.rb', line 14

def code
  @code ||= strings.map(&:code).pack("c*")
end

#complexityObject



26
27
28
# File 'lib/wtf_chord/fingering.rb', line 26

def complexity
  complexity_counter.rate
end

#drawObject



30
31
32
# File 'lib/wtf_chord/fingering.rb', line 30

def draw
  Formatter.new(:default).call(self)
end

#holded_stringsObject



38
39
40
# File 'lib/wtf_chord/fingering.rb', line 38

def holded_strings
  @strings.select(&:holded?)
end

#min_fretObject



46
47
48
# File 'lib/wtf_chord/fingering.rb', line 46

def min_fret
  holded_strings.min.fret
end

#set_fingers(fingers) ⇒ Object



34
35
36
# File 'lib/wtf_chord/fingering.rb', line 34

def set_fingers(fingers)
  fingers.each_with_index { |f, i| f.nil? ? @strings[i].dead : @strings[i].hold_on(f) }
end

#used_stringsObject



42
43
44
# File 'lib/wtf_chord/fingering.rb', line 42

def used_strings
  @strings.reject(&:dead?)
end