Class: KeyboardLayout
Overview
This is a basic keyboard layout.
Instance Attribute Summary collapse
-
#auto_case ⇒ Object
Returns the value of attribute auto_case.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nav_to_key ⇒ Object
Returns the value of attribute nav_to_key.
-
#shift_key ⇒ Object
Returns the value of attribute shift_key.
-
#start_coords ⇒ Object
Returns the value of attribute start_coords.
Instance Method Summary collapse
-
#initialize(key_matrix, start_coords, name: 'default', nav_to_key: nil, auto_case: false) ⇒ KeyboardLayout
constructor
Public: Create a new keyboard layout.
-
#key_matrix(shifted) ⇒ Object
Public: Gets key matrix of the current layout.
Constructor Details
#initialize(key_matrix, start_coords, name: 'default', nav_to_key: nil, auto_case: false) ⇒ KeyboardLayout
Public: Create a new keyboard layout.
key_matrix - Multi-dimensional Array of Strings defining the keyboard layout. start_coords - Array of Integer start coordinates for this layout in [row, col]. name - String name of keyboard layout. nav_to_key - String key used to navigate to this layout (default: nil). auto_case - Boolean indicating whether the keyboard automatically capitalizes words (default: false).
Returns the new KeyboardLayout.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/keyboard/keyboard_layout.rb', line 14 def initialize(key_matrix, start_coords, name: 'default', nav_to_key: nil, auto_case: false) @key_matrix = key_matrix @start_coords = start_coords @name = name @nav_to_key = nav_to_key @auto_case = auto_case @shift_key = nil all_keys = key_matrix.flatten [:SHIFT_LOCK, :SHIFT].each do |shift_key| if all_keys.include?(shift_key) @shift_key = shift_key break end end end |
Instance Attribute Details
#auto_case ⇒ Object
Returns the value of attribute auto_case.
3 4 5 |
# File 'lib/keyboard/keyboard_layout.rb', line 3 def auto_case @auto_case end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/keyboard/keyboard_layout.rb', line 3 def name @name end |
#nav_to_key ⇒ Object
Returns the value of attribute nav_to_key.
3 4 5 |
# File 'lib/keyboard/keyboard_layout.rb', line 3 def nav_to_key @nav_to_key end |
#shift_key ⇒ Object
Returns the value of attribute shift_key.
3 4 5 |
# File 'lib/keyboard/keyboard_layout.rb', line 3 def shift_key @shift_key end |
#start_coords ⇒ Object
Returns the value of attribute start_coords.
3 4 5 |
# File 'lib/keyboard/keyboard_layout.rb', line 3 def start_coords @start_coords end |
Instance Method Details
#key_matrix(shifted) ⇒ Object
Public: Gets key matrix of the current layout.
shifted - Boolean indicating whether the keyboard case is shifted.
Returns the key matrix.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/keyboard/keyboard_layout.rb', line 35 def key_matrix(shifted) if shifted @key_matrix.map do |row| row.map do |key| if key.is_a?(String) key =~ /^[[:upper:]]+$/ ? key.downcase : key.upcase else key end end end else @key_matrix end end |