Class: Butler::IRC::Message
- Inherits:
-
Object
- Object
- Butler::IRC::Message
- Defined in:
- lib/butler/bot.rb
Overview
IRC::User
Instance Attribute Summary collapse
-
#invocation ⇒ Object
the invocation-sequence (e.g. “butler, ”), nil if none was used (e.g. in private messages).
-
#language ⇒ Object
the language of this message, as determined by butler.
Instance Method Summary collapse
-
#arguments ⇒ Object
parses a given string into argument-tokens.
- #butler_initialize ⇒ Object
-
#initialize(*args, &block) ⇒ Message
constructor
A new instance of Message.
-
#post_arguments ⇒ Object
FIXME due to it’s current working, post_arguments will strip formatting Returns the rest of message text after argument == Synopsis “foo bar baz”.post_arguments # => “foo bar baz” “foo bar baz”.post_arguments # => “bar baz” “foo bar baz”.post_arguments # => “baz”.
Constructor Details
#initialize(*args, &block) ⇒ Message
Returns a new instance of Message.
249 250 251 252 253 254 255 |
# File 'lib/butler/bot.rb', line 249 def initialize(*args, &block) butler_initialize(*args, &block) @language = nil @invocation = nil @arguments = nil @post_arguments = nil end |
Instance Attribute Details
#invocation ⇒ Object
the invocation-sequence (e.g. “butler, ”), nil if none was used (e.g. in private messages)
246 247 248 |
# File 'lib/butler/bot.rb', line 246 def invocation @invocation end |
#language ⇒ Object
the language of this message, as determined by butler
242 243 244 |
# File 'lib/butler/bot.rb', line 242 def language @language end |
Instance Method Details
#arguments ⇒ Object
parses a given string into argument-tokens. a token is either a word or a quoted string. escapes are respected. e.g. ‘Hallo “this is token2” “and this "token" is token3”’ would be parsed into: [“hallo”, “this is token2”, “and this "token" is token3”]
260 261 262 263 264 265 266 267 |
# File 'lib/butler/bot.rb', line 260 def arguments return [] unless text # only messages with text can be tokenized to parameters @arguments ||= begin # don't do double-work text[@invocation.length..-1].arguments rescue String::SingleQuoteException => ex ex.pre+[ex.post.join(" ")] end end |
#butler_initialize ⇒ Object
248 |
# File 'lib/butler/bot.rb', line 248 alias butler_initialize initialize |
#post_arguments ⇒ Object
FIXME due to it’s current working, post_arguments will strip formatting Returns the rest of message text after argument
Synopsis
"foo bar baz".post_arguments[0] # => "foo bar baz"
"foo bar baz".post_arguments[1] # => "bar baz"
"foo bar baz".post_arguments[2] # => "baz"
275 276 277 278 |
# File 'lib/butler/bot.rb', line 275 def post_arguments return [] unless text # only messages with text can be tokenized to parameters @post_arguments ||= text[@invocation.length..-1].post_arguments # don't do double-work end |