class Meshchat::Ui::CLI::InputFactory

Constants

COMMAND
WHISPER

Attributes

_cli[RW]
_message_dispatcher[RW]
_message_factory[RW]
_whisper_lock_target[RW]

Public Class Methods

new(message_dispatcher, message_factory, cli) click to toggle source
# 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

Public Instance Methods

clear_whisper_lock() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/meshchat/ui/cli/input_factory.rb, line 18
def is_command?(input)
  input[0, 1] == COMMAND
end
is_whisper?(input) click to toggle source
# File lib/meshchat/ui/cli/input_factory.rb, line 22
def is_whisper?(input)
  input[0, 1] == WHISPER
end
whisper_for_locked_target(input) click to toggle source
# 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) click to toggle source
# File lib/meshchat/ui/cli/input_factory.rb, line 40
def whisper_lock_to(node)
  self._whisper_lock_target = node
end