Class: Vedeu::Input::Keymap Private
- Inherits:
-
Object
- Object
- Vedeu::Input::Keymap
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/input/keymap.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A container class for keys associated with a particular interface.
Instance Attribute Summary collapse
Attributes included from Repositories::Model
Instance Method Summary collapse
-
#add(key) ⇒ void
private
Add a key to the keymap.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#deputy(client = nil) ⇒ Vedeu::Input::DSL
private
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#initialize(attributes = {}) ⇒ Vedeu::Input::Keymap
constructor
private
Returns a new instance of Vedeu::Input::Keymap.
-
#key_defined?(input) ⇒ Boolean
private
Check whether the key is already defined for this keymap.
-
#keys ⇒ Vedeu::Input::Keys
private
Returns the collection of keys defined for this keymap.
-
#use(input) ⇒ Array|Boolean
private
When the given input is registered with this keymap, this method triggers the action associated with the key.
-
#valid?(key) ⇒ Boolean
private
private
Checks that the provided key is not already registered with this keymap.
Methods included from Repositories::Model
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Input::Keymap
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Input::Keymap.
31 32 33 34 35 |
# File 'lib/vedeu/input/keymap.rb', line 31 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String
18 19 20 |
# File 'lib/vedeu/input/keymap.rb', line 18 def name @name end |
Instance Method Details
#add(key) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Add a key to the keymap.
41 42 43 44 45 |
# File 'lib/vedeu/input/keymap.rb', line 41 def add(key) return false unless valid?(key) @keys = keys.add(key) end |
#defaults ⇒ Hash<Symbol => void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default options/attributes for a new instance of this class.
91 92 93 94 95 96 97 |
# File 'lib/vedeu/input/keymap.rb', line 91 def defaults { name: nil, keys: [], repository: Vedeu.keymaps, } end |
#deputy(client = nil) ⇒ Vedeu::Input::DSL
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a DSL instance responsible for defining the DSL methods of this model.
55 56 57 |
# File 'lib/vedeu/input/keymap.rb', line 55 def deputy(client = nil) Vedeu::Input::DSL.new(self, client) end |
#key_defined?(input) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check whether the key is already defined for this keymap.
71 72 73 |
# File 'lib/vedeu/input/keymap.rb', line 71 def key_defined?(input) keys.any? { |key| key.input == input } end |
#keys ⇒ Vedeu::Input::Keys
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the collection of keys defined for this keymap.
62 63 64 |
# File 'lib/vedeu/input/keymap.rb', line 62 def keys Vedeu::Input::Keys.coerce(@keys, self) end |
#use(input) ⇒ Array|Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
When the given input is registered with this keymap, this method triggers the action associated with the key.
80 81 82 83 84 85 86 |
# File 'lib/vedeu/input/keymap.rb', line 80 def use(input) return false unless key_defined?(input) Vedeu.log(type: :input, message: "Key pressed: '#{input}'") keys.select { |key| key.input == input }.map(&:press) end |
#valid?(key) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks that the provided key is not already registered with this keymap.
104 105 106 107 108 109 110 111 112 |
# File 'lib/vedeu/input/keymap.rb', line 104 def valid?(key) return true unless key_defined?(key.input) Vedeu.log(type: :input, message: "Keymap '#{name}' already " \ "defines '#{key.input}'.") false end |