Class: WTFChord::Formatters::Piano1

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

Direct Known Subclasses

Piano

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ Piano1



22
23
24
# File 'lib/wtf_chord/formatters/piano1.rb', line 22

def initialize(keys)
  @pressed_keys = keys
end

Instance Attribute Details

#pressed_keysObject (readonly)

Returns the value of attribute pressed_keys.



20
21
22
# File 'lib/wtf_chord/formatters/piano1.rb', line 20

def pressed_keys
  @pressed_keys
end

Class Method Details

.separatorObject



8
9
10
# File 'lib/wtf_chord/formatters/piano1.rb', line 8

def self.separator
  "\n"
end

.to_procObject



12
13
14
# File 'lib/wtf_chord/formatters/piano1.rb', line 12

def self.to_proc
  proc { |keys| new(keys).draw }
end

.with_rates {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



16
17
18
# File 'lib/wtf_chord/formatters/piano1.rb', line 16

def self.with_rates(*)
  yield(self)
end

Instance Method Details

#actual_notesObject



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

def actual_notes
  actual_strings.map(&:note)
end

#drawObject



26
27
28
29
30
31
# File 'lib/wtf_chord/formatters/piano1.rb', line 26

def draw
  [
    unique_notes.sort.join(" - "),
    keyboard_presentation
  ].join("\n\n")
end

#keyboard_presentationObject



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

def keyboard_presentation
  KeyboardPresentation.press(*unique_notes.map(&:position))
end

#unique_notesObject



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

def unique_notes
  actual_notes.uniq(&:position)
end