class Meshchat::Ui::Command::Ping
Public Class Methods
description()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 6 def self.description 'pings a particular user' end
Public Instance Methods
command_valid?()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 48 def command_valid? parse_ping_command.compact.length == 2 end
handle()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 10 def handle if command_valid? msg = _message_factory.create(Network::Message::PING) field, value = parse_ping_command node = if field == 'location' Node.find_by_location_on_network(lookup_value) else Node.find_by_alias_name(lookup_value) end location = node.try(:location) unless location return Display.alert "#{lookup_value} could not be found" end _message_dispatcher.send_message(node: node, message: msg) else Display.alert usage end end
lookup_field()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 39 def lookup_field sub_command end
lookup_value()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 43 def lookup_value value = command_args.last value if value != sub_command end
parse_ping_command()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 52 def parse_ping_command @parsed_args ||= if lookup_field == 'location' || lookup_field == 'alias' [lookup_field, lookup_value] elsif lookup_field =~ /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/ ['location', lookup_field] else ['alias', lookup_field] end end
usage()
click to toggle source
# File lib/meshchat/ui/command/ping.rb, line 35 def usage 'Usage: /ping {field} {value} e.g.: /ping alias neurotek or /ping location 10.10.10.10:8080' end