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 ⇒ String|Symbol readonly protected
- #repository ⇒ Vedeu::Repository readonly protected
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_key? ⇒ Boolean
private
Is the key a global key?.
-
#initialize(key = nil, name = nil, repository = nil) ⇒ Mapper
constructor
Returns a new instance of Vedeu::Mapper.
-
#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
Returns a boolean indicating that the key is registered to the current keymap or the global or system keymap.
-
#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_key? ⇒ Boolean
private
Is the key a system key?.
-
#valid? ⇒ Boolean
Returns a boolean indicating that the key is not registered to the current keymap, the global keymap or the system keymap.
Constructor Details
#initialize(key = nil, name = nil, repository = nil) ⇒ Mapper
Returns a new instance of Vedeu::Mapper.
35 36 37 38 39 |
# File 'lib/vedeu/input/mapper.rb', line 35 def initialize(key = nil, name = nil, repository = nil) @key = key @name = name @repository = repository || Vedeu.keymaps end |
Instance Attribute Details
#key ⇒ String|Symbol (readonly, protected)
71 72 73 |
# File 'lib/vedeu/input/mapper.rb', line 71 def key @key end |
#repository ⇒ Vedeu::Repository (readonly, protected)
75 76 77 |
# File 'lib/vedeu/input/mapper.rb', line 75 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.
12 13 14 15 16 |
# File 'lib/vedeu/input/mapper.rb', line 12 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.
23 24 25 26 27 |
# File 'lib/vedeu/input/mapper.rb', line 23 def self.valid?(key = nil, name = nil) return false unless key new(key, name).valid? end |
Instance Method Details
#global_key? ⇒ Boolean (private)
Is the key a global key?
82 83 84 |
# File 'lib/vedeu/input/mapper.rb', line 82 def global_key? key_defined?('_global_') end |
#key_defined?(named = name) ⇒ Boolean (private)
Is the key defined in the named keymap?
97 98 99 |
# File 'lib/vedeu/input/mapper.rb', line 97 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.
105 106 107 |
# File 'lib/vedeu/input/mapper.rb', line 105 def keymap(named = name) repository.find(named) end |
#keymap?(named = name) ⇒ Boolean (private)
Does the keymaps repository have the named keymap already registered?
113 114 115 |
# File 'lib/vedeu/input/mapper.rb', line 113 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 or system keymap.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vedeu/input/mapper.rb', line 45 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.
121 122 123 |
# File 'lib/vedeu/input/mapper.rb', line 121 def name @name || Vedeu.focus end |
#system_key? ⇒ Boolean (private)
Is the key a system key?
89 90 91 |
# File 'lib/vedeu/input/mapper.rb', line 89 def system_key? key_defined?('_system_') end |
#valid? ⇒ Boolean
Returns a boolean indicating that the key is not registered to the current keymap, the global keymap or the system keymap.
61 62 63 64 65 |
# File 'lib/vedeu/input/mapper.rb', line 61 def valid? return false if !key || key_defined? || global_key? || system_key? true end |