class Pepito::Message
Message
received by an adapter
Attributes
body[R]
The text received. @return [String]
command[R]
The command part of the message. Example: body is -> “pepito info”, command is “info”. @return [String, nil] Returns nil if command could not be parsed.
robot[R]
The currently running robot. @return [Pepito::Robot]
source[R]
The source of the message. @return [Pepito::Source]
Public Class Methods
new(robot, source, body)
click to toggle source
@param robot [Pepito::Robot] The currently running robot. @param source [Pepito::Source] The source of the message. @param body [String] The text received. @return [void]
# File lib/pepito/message.rb, line 25 def initialize(robot, source, body) @robot = robot @source = source @body = body @command = parse_command end
Public Instance Methods
command?()
click to toggle source
Returns whether a command exists or not. @return [Boolean]
# File lib/pepito/message.rb, line 35 def command? @command.nil? ? false : true end
match_route?(route)
click to toggle source
Returns whether a message matches a route or not @return [Boolean]
# File lib/pepito/message.rb, line 41 def match_route?(route) return true if !route.command && route.pattern.match(body) return true if route.command && command? && route.pattern.match(command) false end
Private Instance Methods
parse_command()
click to toggle source
Parses the command from the body attribute. @return [String] The command string
# File lib/pepito/message.rb, line 51 def parse_command return nil if @robot.name.nil? || @robot.name.empty? command_data = /^#{@robot.name}\s?(?<command>.*)$/.match(@body) command_data[:command] unless command_data.nil? end