Class: Fir::KeyCommand
- Inherits:
-
Object
show all
- Defined in:
- lib/fir/key_command/key_command.rb
Direct Known Subclasses
BackspaceCommand, CtrlACommand, CtrlCCommand, CtrlDCommand, CtrlECommand, CtrlVCommand, CtrlZCommand, DownArrowCommand, EnterCommand, LeftArrowCommand, RightArrowCommand, SingleKeyCommand, TabCommand, UpArrowCommand
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(character, state) ⇒ KeyCommand
Returns a new instance of KeyCommand.
39
40
41
42
|
# File 'lib/fir/key_command/key_command.rb', line 39
def initialize(character, state)
@character = character
@state = state
end
|
Instance Attribute Details
#character ⇒ Object
Returns the value of attribute character.
6
7
8
|
# File 'lib/fir/key_command/key_command.rb', line 6
def character
@character
end
|
#state ⇒ Object
Returns the value of attribute state.
7
8
9
|
# File 'lib/fir/key_command/key_command.rb', line 7
def state
@state
end
|
Class Method Details
.build(character, state) ⇒ Object
9
10
11
|
# File 'lib/fir/key_command/key_command.rb', line 9
def self.build(character, state)
find(character).new(character, state)
end
|
.character_regex ⇒ Object
35
36
37
|
# File 'lib/fir/key_command/key_command.rb', line 35
def self.character_regex
/.*/
end
|
.for(character, state) ⇒ Object
13
14
15
16
17
|
# File 'lib/fir/key_command/key_command.rb', line 13
def self.for(character, state)
registry.find do |candidate|
candidate.handles?(character)
end.new(character, state)
end
|
.handles?(character) ⇒ Boolean
31
32
33
|
# File 'lib/fir/key_command/key_command.rb', line 31
def self.handles?(character)
Array(character_regex).any? { |re| re.match(character) }
end
|
.inherited(candidate) ⇒ Object
27
28
29
|
# File 'lib/fir/key_command/key_command.rb', line 27
def self.inherited(candidate)
register(candidate)
end
|
.register(candidate) ⇒ Object
23
24
25
|
# File 'lib/fir/key_command/key_command.rb', line 23
def self.register(candidate)
registry.unshift(candidate)
end
|
.registry ⇒ Object
19
20
21
|
# File 'lib/fir/key_command/key_command.rb', line 19
def self.registry
@registry ||= [KeyCommand]
end
|
Instance Method Details
#execute ⇒ Object
44
45
46
|
# File 'lib/fir/key_command/key_command.rb', line 44
def execute
execute_hook(state.clone)
end
|
#execute_hook(new_state) ⇒ Object
48
49
50
|
# File 'lib/fir/key_command/key_command.rb', line 48
def execute_hook(new_state)
new_state
end
|