Class: Ruboty::Message
- Inherits:
-
Object
- Object
- Ruboty::Message
- Defined in:
- lib/ruboty/message.rb
Instance Attribute Summary collapse
-
#match_data ⇒ Object
readonly
Returns the value of attribute match_data.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #body ⇒ Object
- #from ⇒ Object
-
#from_name ⇒ String
User identifier in the Chat service.
-
#initialize(original) ⇒ Message
constructor
A new instance of Message.
- #match(pattern) ⇒ Object
- #reply(body, options = {}) ⇒ Object
- #robot ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(original) ⇒ Message
Returns a new instance of Message.
8 9 10 |
# File 'lib/ruboty/message.rb', line 8 def initialize(original) @original = original end |
Instance Attribute Details
#match_data ⇒ Object (readonly)
Returns the value of attribute match_data.
3 4 5 |
# File 'lib/ruboty/message.rb', line 3 def match_data @match_data end |
Instance Method Details
#[](index) ⇒ Object
38 39 40 |
# File 'lib/ruboty/message.rb', line 38 def [](index) match_data[index] end |
#body ⇒ Object
12 13 14 |
# File 'lib/ruboty/message.rb', line 12 def body @original[:body] end |
#from ⇒ Object
16 17 18 |
# File 'lib/ruboty/message.rb', line 16 def from @original[:from] end |
#from_name ⇒ String
Note:
Some chat service such as XMPP has 2 types of address, address and username
Returns User identifier in the Chat service.
22 23 24 |
# File 'lib/ruboty/message.rb', line 22 def from_name @original[:from_name] || from end |
#match(pattern) ⇒ Object
34 35 36 |
# File 'lib/ruboty/message.rb', line 34 def match(pattern) @match_data = pattern.match(body) end |
#reply(body, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/ruboty/message.rb', line 42 def reply(body, = {}) attributes = { body: body, from: to, to: from, original: original }.merge() robot.say(attributes) end |
#robot ⇒ Object
26 27 28 |
# File 'lib/ruboty/message.rb', line 26 def robot @original[:robot] end |
#to ⇒ Object
30 31 32 |
# File 'lib/ruboty/message.rb', line 30 def to @original[:to] end |