Class: Vedeu::Input::Mapper
- Inherits:
-
Object
- Object
- Vedeu::Input::Mapper
- Extended by:
- Common
- Defined in:
- lib/vedeu/input/mapper.rb
Overview
Maps keys to keymaps.
Instance Attribute Summary collapse
- #key ⇒ NilClass|String|Symbol|Vedeu::Cursors::Cursor readonly protected
- #repository ⇒ Vedeu::Repositories::Repository readonly protected
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.keypress(key = nil, name = nil) ⇒ Boolean
Takes a key as a keypress and sends it to registered keymaps.
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- .registered?(key = nil, name = nil) ⇒ Boolean
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.valid?(key = nil, name = nil) ⇒ Boolean
Checks a key is valid; i.e.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
Instance Method Summary collapse
-
#global_key? ⇒ Boolean
private
Is the key a global key?.
-
#initialize(key = nil, name = nil, repository = nil) ⇒ Vedeu::Input::Mapper
constructor
Returns a new instance of Vedeu::Input::Mapper.
-
#key_defined?(named = name) ⇒ Boolean
(also: #registered?)
Is the key defined in the named keymap?.
-
#keymap(named = name) ⇒ Vedeu::Input::Keymap
private
Fetch the named keymap from the repository.
-
#keymap?(named = name) ⇒ Boolean
private
Does the keymaps repository have the named keymap already registered?.
-
#keypress ⇒ Boolean
Returns a boolean indicating that the key is registered to the current keymap, or the global keymap.
- #log_message(key) ⇒ String private
-
#name ⇒ String|NilClass
(also: #interface)
private
With a name, we check the keymap with that name, otherwise we use the name of the interface currently in focus.
-
#valid? ⇒ Boolean
Returns a boolean indicating that the key is not registered to the current keymap, or the global keymap.
Constructor Details
#initialize(key = nil, name = nil, repository = nil) ⇒ Vedeu::Input::Mapper
Returns a new instance of Vedeu::Input::Mapper.
63 64 65 66 67 |
# File 'lib/vedeu/input/mapper.rb', line 63 def initialize(key = nil, name = nil, repository = nil) @key = key @name = name @repository = repository || Vedeu.keymaps end |
Instance Attribute Details
#key ⇒ NilClass|String|Symbol|Vedeu::Cursors::Cursor (readonly, protected)
110 111 112 |
# File 'lib/vedeu/input/mapper.rb', line 110 def key @key end |
#repository ⇒ Vedeu::Repositories::Repository (readonly, protected)
114 115 116 |
# File 'lib/vedeu/input/mapper.rb', line 114 def repository @repository end |
Class 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.
.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.
.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.
.keypress(key = nil, name = nil) ⇒ Boolean
Takes a key as a keypress and sends it to registered keymaps. If found, the associated action is fired, otherwise, we move to the next keymap or return false.
24 25 26 |
# File 'lib/vedeu/input/mapper.rb', line 24 def keypress(key = nil, name = nil) new(key, name).keypress 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.
.registered?(key = nil, name = nil) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vedeu/input/mapper.rb', line 32 def registered?(key = nil, name = nil) fail Vedeu::Error::MissingRequired, 'Cannot check whether a key is registered to a keymap without ' \ 'the key.' if absent?(key) fail Vedeu::Error::MissingRequired, 'Cannot check whether a key is registered to a keymap without ' \ 'the keymap name.' if absent?(name) new(key, name).registered? end |
.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.
.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.
.valid?(key = nil, name = nil) ⇒ Boolean
Checks a key is valid; i.e. not already registered to a keymap. When the key is registered, then the key is invalid and cannot be used again.
49 50 51 52 53 |
# File 'lib/vedeu/input/mapper.rb', line 49 def valid?(key = nil, name = nil) return false unless key new(key, name).valid? 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.
Instance Method Details
#global_key? ⇒ Boolean (private)
Is the key a global key?
121 122 123 |
# File 'lib/vedeu/input/mapper.rb', line 121 def global_key? key_defined?('_global_') end |
#key_defined?(named = name) ⇒ Boolean Also known as: registered?
Is the key defined in the named keymap?
91 92 93 |
# File 'lib/vedeu/input/mapper.rb', line 91 def key_defined?(named = name) keymap?(named) && keymap(named).key_defined?(key) end |
#keymap(named = name) ⇒ Vedeu::Input::Keymap (private)
Fetch the named keymap from the repository.
129 130 131 |
# File 'lib/vedeu/input/mapper.rb', line 129 def keymap(named = name) repository.find(named) end |
#keymap?(named = name) ⇒ Boolean (private)
Does the keymaps repository have the named keymap already registered?
138 139 140 |
# File 'lib/vedeu/input/mapper.rb', line 138 def keymap?(named = name) repository.registered?(named) end |
#keypress ⇒ Boolean
Returns a boolean indicating that the key is registered to the current keymap, or the global keymap.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vedeu/input/mapper.rb', line 73 def keypress Vedeu.trigger(:key, key) return false unless key return true if key_defined? && keymap.use(key) return true if global_key? && keymap('_global_').use(key) Vedeu.log(type: :input, message: (key)) false end |
#log_message(key) ⇒ String (private)
144 145 146 147 148 149 150 151 152 |
# File 'lib/vedeu/input/mapper.rb', line 144 def (key) if key.is_a?(Vedeu::Cursors::Cursor) "Click detected: x: #{key.x} y: #{key.y}" else "Key detected: #{key.inspect}" end end |
#name ⇒ String|NilClass (private) Also known as: interface
With a name, we check the keymap with that name, otherwise we use the name of the interface currently in focus.
158 159 160 |
# File 'lib/vedeu/input/mapper.rb', line 158 def name @name || Vedeu.focus end |
#valid? ⇒ Boolean
Returns a boolean indicating that the key is not registered to the current keymap, or the global keymap.
100 101 102 103 104 |
# File 'lib/vedeu/input/mapper.rb', line 100 def valid? return false if !key || key_defined? || global_key? true end |