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 collapse

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:



9
10
11
12
13
14
15
# File 'lib/wtf_chord/fingering.rb', line 9

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

Instance Attribute Details

#extra_complexityObject

Returns the value of attribute extra_complexity.



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

def extra_complexity
  @extra_complexity
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/wtf_chord/fingering.rb', line 21

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

#codeObject



17
18
19
# File 'lib/wtf_chord/fingering.rb', line 17

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

#complexityObject



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

def complexity
  complexity_counter.rate
end

#drawObject



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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  super || self == other
end

#find_used_string_for(note) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/wtf_chord/fingering.rb', line 61

def find_used_string_for(note)
  used = used_strings
  if idx = used.index(note)
    string = used[idx]
    yield(strings.index(string), string)
  end
end

#hashObject



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

def hash
  strings.map(&:code).hash
end

#holded_stringsObject



53
54
55
# File 'lib/wtf_chord/fingering.rb', line 53

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

#min_fretObject



69
70
71
# File 'lib/wtf_chord/fingering.rb', line 69

def min_fret
  holded_strings.min.fret
end

#set_fingers(fingers) ⇒ Object



49
50
51
# File 'lib/wtf_chord/fingering.rb', line 49

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

#used_keysObject



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

def used_keys
  used_strings.map(&:note).map(&:key).uniq.join
end

#used_stringsObject



57
58
59
# File 'lib/wtf_chord/fingering.rb', line 57

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