Class: Meshchat::Ui::CLI::InputFactory
- Inherits:
-
Object
- Object
- Meshchat::Ui::CLI::InputFactory
- Defined in:
- lib/meshchat/ui/cli/input_factory.rb
Constant Summary collapse
- WHISPER =
'@'
- COMMAND =
'/'
Instance Attribute Summary collapse
-
#_cli ⇒ Object
Returns the value of attribute _cli.
-
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
-
#_message_factory ⇒ Object
Returns the value of attribute _message_factory.
-
#_whisper_lock_target ⇒ Object
Returns the value of attribute _whisper_lock_target.
Instance Method Summary collapse
- #clear_whisper_lock ⇒ Object
- #create(for_input: nil, with_class: nil) ⇒ Object
- #create_for_input(input) ⇒ Object
- #create_with_class(input, klass) ⇒ Object
-
#initialize(message_dispatcher, message_factory, cli) ⇒ InputFactory
constructor
A new instance of InputFactory.
- #is_command?(input) ⇒ Boolean
- #is_whisper?(input) ⇒ Boolean
- #whisper_for_locked_target(input) ⇒ Object
- #whisper_lock_to(node) ⇒ Object
Constructor Details
#initialize(message_dispatcher, message_factory, cli) ⇒ InputFactory
Returns a new instance of InputFactory.
12 13 14 15 16 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 12 def initialize(, , cli) self. = self. = self._cli = cli end |
Instance Attribute Details
#_cli ⇒ Object
Returns the value of attribute _cli.
9 10 11 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9 def _cli @_cli end |
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
9 10 11 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9 def @_message_dispatcher end |
#_message_factory ⇒ Object
Returns the value of attribute _message_factory.
9 10 11 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9 def @_message_factory end |
#_whisper_lock_target ⇒ Object
Returns the value of attribute _whisper_lock_target.
10 11 12 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 10 def _whisper_lock_target @_whisper_lock_target end |
Instance Method Details
#clear_whisper_lock ⇒ Object
36 37 38 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 36 def clear_whisper_lock self._whisper_lock_target = nil end |
#create(for_input: nil, with_class: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 26 def create(for_input: nil, with_class: nil) return create_with_class(for_input, with_class) if with_class create_for_input(for_input) end |
#create_for_input(input) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 44 def create_for_input(input) klass = if is_command?(input) Command::Base elsif is_whisper?(input) Command::Whisper else return whisper_for_locked_target(input) if _whisper_lock_target Command::Chat end create_with_class(input, klass) end |
#create_with_class(input, klass) ⇒ Object
32 33 34 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 32 def create_with_class(input, klass) klass.new(input, , , self) end |
#is_command?(input) ⇒ Boolean
18 19 20 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 18 def is_command?(input) input[0, 1] == COMMAND end |
#is_whisper?(input) ⇒ Boolean
22 23 24 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 22 def is_whisper?(input) input[0, 1] == WHISPER end |
#whisper_for_locked_target(input) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 58 def whisper_for_locked_target(input) command = Command::Whisper.new( input, , , self ) command._target_node = _whisper_lock_target command end |
#whisper_lock_to(node) ⇒ Object
40 41 42 |
# File 'lib/meshchat/ui/cli/input_factory.rb', line 40 def whisper_lock_to(node) self._whisper_lock_target = node end |