Class: WTFChord::Keyboard

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

Constant Summary collapse

KEYS =
%w(C C# D D# E F F# G G# A Bb B)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(octaves = 1..5) ⇒ Keyboard

Returns a new instance of Keyboard.



11
12
13
# File 'lib/wtf_chord/keyboard.rb', line 11

def initialize(octaves = 1..5)
  @keys = octaves.to_a.product(KEYS).map { |(o, k)| PianoKey.new("#{k}#{o}") }
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



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

def keys
  @keys
end

Instance Method Details

#[](idx) ⇒ Object



15
16
17
18
19
# File 'lib/wtf_chord/keyboard.rb', line 15

def [] idx
  case idx
  when 1..@keys.size then @keys[~-idx]
  end
end