Class: Ant::Bot::Adapter::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/ant/bot/adapters/debug.rb

Overview

This class simulates a message chat with a user.

Instance Method Summary collapse

Constructor Details

#initialize(messages, name, echo) ⇒ Channel

It is build from an array of raw messages, the name of the channel and the config to enable debug messages



32
33
34
35
36
37
# File 'lib/ant/bot/adapters/debug.rb', line 32

def initialize(messages, name, echo)
  @state = :open
  @pending_messages = messages
  @name = name
  @echo = echo
end

Instance Method Details

#answer(message) ⇒ Object

receives the answer from the bot



67
68
69
70
# File 'lib/ant/bot/adapters/debug.rb', line 67

def answer(message)
  send_data(message)
  @state = :open
end

#echo=(toogle) ⇒ Object



62
63
64
# File 'lib/ant/bot/adapters/debug.rb', line 62

def echo=(toogle)
  @echo = toogle
end

#empty?Boolean

Checks if there are still messages in the channel

Returns:

  • (Boolean)


45
46
47
# File 'lib/ant/bot/adapters/debug.rb', line 45

def empty?
  @pending_messages.empty?
end

#open?Boolean

Checks if there are messages open or that has not been answered

Returns:

  • (Boolean)


40
41
42
# File 'lib/ant/bot/adapters/debug.rb', line 40

def open?
  @state == :open
end

#read_messageObject

returns the next message in the buffer



50
51
52
53
# File 'lib/ant/bot/adapters/debug.rb', line 50

def read_message
  @state = :closed
  DebugMessage.new(@pending_messages.shift, @name)
end

#send_data(message) ⇒ Object



55
56
57
58
59
60
# File 'lib/ant/bot/adapters/debug.rb', line 55

def send_data(message)
  return unless @echo

  puts "Sending message to channel: #{@name}"
  puts message
end