Class: Meshchat::Ui::CLI::InputFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/meshchat/ui/cli/input_factory.rb

Constant Summary collapse

WHISPER =
'@'
COMMAND =
'/'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(message_dispatcher, message_factory, cli)
  self._message_dispatcher = message_dispatcher
  self._message_factory    = message_factory
  self._cli                = cli
end

Instance Attribute Details

#_cliObject

Returns the value of attribute _cli.



9
10
11
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9

def _cli
  @_cli
end

#_message_dispatcherObject

Returns the value of attribute _message_dispatcher.



9
10
11
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9

def _message_dispatcher
  @_message_dispatcher
end

#_message_factoryObject

Returns the value of attribute _message_factory.



9
10
11
# File 'lib/meshchat/ui/cli/input_factory.rb', line 9

def _message_factory
  @_message_factory
end

#_whisper_lock_targetObject

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_lockObject



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, _message_dispatcher, _message_factory, self)
end

#is_command?(input) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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, _message_dispatcher, _message_factory, 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