Class: Del::Message

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

Overview

An XMPP Message

Constant Summary collapse

PREFIX =
'/code'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, robot:, source:) ⇒ Message

Returns a new instance of Message.



9
10
11
12
13
# File 'lib/del/message.rb', line 9

def initialize(text, robot:, source:)
  @text = text
  @robot = robot
  @source = source
end

Instance Attribute Details

#robotObject (readonly)

Returns the value of attribute robot.



7
8
9
# File 'lib/del/message.rb', line 7

def robot
  @robot
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/del/message.rb', line 7

def source
  @source
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/del/message.rb', line 7

def text
  @text
end

Instance Method Details

#execute_shell(command) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/del/message.rb', line 19

def execute_shell(command)
  reply("Okay, I'm on it!")
  ShellCommand.new(command).run do |line|
    if block_given?
      yield line
    else
      reply("#{PREFIX} #{line}")
    end
  end
end

#reply(message) ⇒ Object



15
16
17
# File 'lib/del/message.rb', line 15

def reply(message)
  source.reply(robot, message)
end

#to_sObject



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

def to_s
  "#{source}: #{text}"
end