Class: Ruboty::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dataObject (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

#bodyObject


12
13
14
# File 'lib/ruboty/message.rb', line 12

def body
  @original[:body]
end

#fromObject


16
17
18
# File 'lib/ruboty/message.rb', line 16

def from
  @original[:from]
end

#from_nameString

Note:

Some chat service such as XMPP has 2 types of address, address and username

Returns User identifier in the Chat service

Returns:

  • (String)

    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, options = {})
  attributes = { body: body, from: to, to: from, original: original }.merge(options)
  robot.say(attributes)
end

#robotObject


26
27
28
# File 'lib/ruboty/message.rb', line 26

def robot
  @original[:robot]
end

#toObject


30
31
32
# File 'lib/ruboty/message.rb', line 30

def to
  @original[:to]
end