Class: Legion::TTY::Hotkeys
- Inherits:
-
Object
- Object
- Legion::TTY::Hotkeys
- Defined in:
- lib/legion/tty/hotkeys.rb
Instance Method Summary collapse
-
#handle(key) ⇒ Object
rubocop:disable Naming/PredicateMethod.
-
#initialize ⇒ Hotkeys
constructor
A new instance of Hotkeys.
-
#list ⇒ Object
rubocop:enable Naming/PredicateMethod.
- #register(key, description, &block) ⇒ Object
Constructor Details
#initialize ⇒ Hotkeys
Returns a new instance of Hotkeys.
6 7 8 |
# File 'lib/legion/tty/hotkeys.rb', line 6 def initialize @bindings = {} end |
Instance Method Details
#handle(key) ⇒ Object
rubocop:disable Naming/PredicateMethod
15 16 17 18 19 20 21 |
# File 'lib/legion/tty/hotkeys.rb', line 15 def handle(key) binding_entry = @bindings[key] return false unless binding_entry binding_entry[:action].call true end |
#list ⇒ Object
rubocop:enable Naming/PredicateMethod
24 25 26 |
# File 'lib/legion/tty/hotkeys.rb', line 24 def list @bindings.map { |key, b| { key: key, description: b[:description] } } end |
#register(key, description, &block) ⇒ Object
10 11 12 |
# File 'lib/legion/tty/hotkeys.rb', line 10 def register(key, description, &block) @bindings[key] = { description: description, action: block } end |