Class: Vedeu::Mapper
- Inherits:
-
Object
- Object
- Vedeu::Mapper
- Defined in:
- lib/vedeu/input/mapper.rb
Overview
Maps keys to keymaps.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
private
Returns the value of attribute key.
-
#repository ⇒ Object
readonly
private
Returns the value of attribute repository.
Class Method Summary collapse
-
.keypress(key = nil, name = nil) ⇒ Boolean
Takes a key as a keypress and sends it to registered keymaps.
-
.valid?(key = nil, name = nil) ⇒ Boolean
Checks a key is valid; i.e.
Instance Method Summary collapse
-
#global ⇒ String
private
Return the name of the global keymap.
-
#global_key? ⇒ Boolean
private
Is the key a global key?.
- #initialize(key = nil, name = nil, repository = nil) ⇒ Mapper constructor
-
#key_defined?(named = name) ⇒ Boolean
private
Is the key defined in the named keymap?.
-
#keymap(named = name) ⇒ 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
-
#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.
-
#system ⇒ String
private
Return the name of the system keymap.
-
#system_key? ⇒ Boolean
private
Is the key a system key?.
- #valid? ⇒ Boolean
Constructor Details
Instance Attribute Details
#key ⇒ Object (readonly, private)
Returns the value of attribute key.
66 67 68 |
# File 'lib/vedeu/input/mapper.rb', line 66 def key @key end |
#repository ⇒ Object (readonly, private)
Returns the value of attribute repository.
66 67 68 |
# File 'lib/vedeu/input/mapper.rb', line 66 def repository @repository end |
Class Method Details
.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, if not, we move to the next keymap or return false.
14 15 16 17 18 |
# File 'lib/vedeu/input/mapper.rb', line 14 def self.keypress(key = nil, name = nil) return false unless key new(key, name).keypress end |
.valid?(key = nil, name = nil) ⇒ Boolean
Checks a key is valid; i.e. not already registered to a keymap. If the key is registered, then the key is invalid and cannot be used again.
26 27 28 29 30 |
# File 'lib/vedeu/input/mapper.rb', line 26 def self.valid?(key = nil, name = nil) return false unless key new(key, name).valid? end |
Instance Method Details
#global ⇒ String (private)
Return the name of the global keymap.
118 119 120 |
# File 'lib/vedeu/input/mapper.rb', line 118 def global '_global_' end |
#global_key? ⇒ Boolean (private)
Is the key a global key?
71 72 73 |
# File 'lib/vedeu/input/mapper.rb', line 71 def global_key? key_defined?(global) end |
#key_defined?(named = name) ⇒ Boolean (private)
Is the key defined in the named keymap?
86 87 88 |
# File 'lib/vedeu/input/mapper.rb', line 86 def key_defined?(named = name) keymap?(named) && keymap(named).key_defined?(key) end |
#keymap(named = name) ⇒ Keymap (private)
Fetch the named keymap from the repository.
94 95 96 |
# File 'lib/vedeu/input/mapper.rb', line 94 def keymap(named = name) repository.find(named) end |
#keymap?(named = name) ⇒ Boolean (private)
Does the keymaps repository have the named keymap already registered?
102 103 104 |
# File 'lib/vedeu/input/mapper.rb', line 102 def keymap?(named = name) repository.registered?(named) end |
#keypress ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vedeu/input/mapper.rb', line 43 def keypress return false unless key return true if key_defined? && keymap.use(key) return true if global_key? && keymap(global).use(key) return true if system_key? && keymap(system).use(key) false 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.
110 111 112 |
# File 'lib/vedeu/input/mapper.rb', line 110 def name @name || Vedeu.focus end |
#system ⇒ String (private)
Return the name of the system keymap.
125 126 127 |
# File 'lib/vedeu/input/mapper.rb', line 125 def system '_system_' end |
#system_key? ⇒ Boolean (private)
Is the key a system key?
78 79 80 |
# File 'lib/vedeu/input/mapper.rb', line 78 def system_key? key_defined?(system) end |
#valid? ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/vedeu/input/mapper.rb', line 56 def valid? return false unless key return false if key_defined? || global_key? || system_key? true end |