Class: MeshChat::CLI::Input
- Inherits:
-
Object
- Object
- MeshChat::CLI::Input
- Defined in:
- lib/meshchat/cli/input.rb
Direct Known Subclasses
Constant Summary collapse
- WHISPER =
'@'- COMMAND =
'/'
Instance Attribute Summary collapse
-
#_input ⇒ Object
Returns the value of attribute _input.
Class Method Summary collapse
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(input) ⇒ Input
constructor
A new instance of Input.
Constructor Details
#initialize(input) ⇒ Input
Returns a new instance of Input.
32 33 34 |
# File 'lib/meshchat/cli/input.rb', line 32 def initialize(input) self._input = input.chomp end |
Instance Attribute Details
#_input ⇒ Object
Returns the value of attribute _input.
6 7 8 |
# File 'lib/meshchat/cli/input.rb', line 6 def _input @_input end |
Class Method Details
.create(input) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/meshchat/cli/input.rb', line 9 def create(input) klass = if is_command(input) Command::Base elsif is_whisper?(input) Command::Whisper else # TODO: maybe change this to a chat command? CLI::Input end klass.new(input) end |
.is_command(input) ⇒ Object
23 24 25 |
# File 'lib/meshchat/cli/input.rb', line 23 def is_command(input) input[0, 1] == COMMAND end |
.is_whisper?(input) ⇒ Boolean
27 28 29 |
# File 'lib/meshchat/cli/input.rb', line 27 def is_whisper?(input) input[0, 1] == WHISPER end |
Instance Method Details
#handle ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/meshchat/cli/input.rb', line 36 def handle return if _input.empty? servers = Node.online if !servers.empty? m = Message::Chat.new( message: _input ) Display.chat m.display # if sending to all, iterate thorugh list of # servers, and send to each one # TODO: do this async so that one server doesn't block # the rest of the servers from receiving the messages servers.each do |entry| Net::Client.send(node: entry, message: m) end else Display.warning 'you have no servers' end end |