Class: Vedeu::Input::Keymap
- Inherits:
-
Object
- Object
- Vedeu::Input::Keymap
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/input/keymap.rb
Overview
A container class for keys associated with a particular interface.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#add(key) ⇒ void
Add a key to the keymap.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#defaults ⇒ Hash<Symbol => Array|String|Vedeu::Input::Repository]
private
Returns the default options/attributes for this class.
-
#deputy(client = nil) ⇒ Vedeu::Input::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(attributes = {}) ⇒ Vedeu::Input::Keymap
constructor
Returns a new instance of Vedeu::Input::Keymap.
-
#key_defined?(input) ⇒ Boolean
Check whether the key is already defined for this keymap.
-
#keys ⇒ Vedeu::Input::Keys
Returns the collection of keys defined for this keymap.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store(&block) ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#use(input) ⇒ Array|Boolean
When the given input is registered with this keymap, this method triggers the action associated with the key.
-
#valid?(key) ⇒ Boolean
private
Checks that the provided key is not already registered with this keymap.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Input::Keymap
Returns a new instance of Vedeu::Input::Keymap.
29 30 31 32 33 |
# File 'lib/vedeu/input/keymap.rb', line 29 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String
16 17 18 |
# File 'lib/vedeu/input/keymap.rb', line 16 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable is nil or empty.
#add(key) ⇒ void
This method returns an undefined value.
Add a key to the keymap.
39 40 41 42 43 |
# File 'lib/vedeu/input/keymap.rb', line 39 def add(key) return false unless valid?(key) @keys = keys.add(key) end |
#become(klass, attributes) ⇒ Class Originally defined in module Common
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.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Boolean.
#defaults ⇒ Hash<Symbol => Array|String|Vedeu::Input::Repository] (private)
Returns the default options/attributes for this class.
91 92 93 94 95 96 97 |
# File 'lib/vedeu/input/keymap.rb', line 91 def defaults { name: '', keys: [], repository: Vedeu.keymaps, } end |
#deputy(client = nil) ⇒ Vedeu::Input::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
53 54 55 |
# File 'lib/vedeu/input/keymap.rb', line 53 def deputy(client = nil) Vedeu::Input::DSL.new(self, client) end |
#escape?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value should be considered false.
#hash?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Hash.
#key_defined?(input) ⇒ Boolean
Check whether the key is already defined for this keymap.
69 70 71 |
# File 'lib/vedeu/input/keymap.rb', line 69 def key_defined?(input) keys.any? { |key| key.input == input } end |
#keys ⇒ Vedeu::Input::Keys
Returns the collection of keys defined for this keymap.
60 61 62 |
# File 'lib/vedeu/input/keymap.rb', line 60 def keys Vedeu::Input::Keys.coerce(@keys, self) end |
#line_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::Line.
#numeric?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Fixnum.
#present?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable has a useful value.
#snake_case(klass) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
#store(&block) ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#stream_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Fixnum.
#truthy?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value should be considered true.
#use(input) ⇒ Array|Boolean
When the given input is registered with this keymap, this method triggers the action associated with the key.
78 79 80 81 82 83 84 |
# File 'lib/vedeu/input/keymap.rb', line 78 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)
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 |
#view_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::View.