Class: Ant::Bot::Adapter::Debug
- Inherits:
-
Object
- Object
- Ant::Bot::Adapter::Debug
- Defined in:
- lib/ant/bot/adapters/debug.rb
Overview
This adapter is intended to be used on unit tests and development.
Defined Under Namespace
Classes: NoMoreMessageException
Instance Method Summary collapse
-
#channel(name) ⇒ Object
removes prefix from channel id.
-
#echo=(toogle) ⇒ Object
changes echo config.
-
#initialize(configs) ⇒ Debug
constructor
It receives a hash with the configurations: - name: the name of the channel - channels a key value, where the key is a name and the value the list of the messages in the channel.
-
#read_message ⇒ Object
Interface for receiving message.
-
#send_audio(channel_name, audio_url) ⇒ Object
interface for sending uadio.
-
#send_image(channel_name, image_url) ⇒ Object
interface for sending image.
-
#send_message(channel_name, contents) ⇒ Object
interface for sending messages.
-
#send_video(channel_name, video_url) ⇒ Object
interface for sending video.
Constructor Details
#initialize(configs) ⇒ Debug
It receives a hash with the configurations:
-
name: the name of the channel
-
channels a key value, where the key is a name and the value the list of the messages in the channel.
-
echo: a flag to enable debug messages.
88 89 90 91 92 93 |
# File 'lib/ant/bot/adapters/debug.rb', line 88 def initialize(configs) @channels = {} configs['channels'].each do |name, | @channels[name] = Channel.new(, name, configs['echo']) end end |
Instance Method Details
#channel(name) ⇒ Object
removes prefix from channel id
112 113 114 |
# File 'lib/ant/bot/adapters/debug.rb', line 112 def channel(name) @channels[name.gsub('debug_message__', '')] end |
#echo=(toogle) ⇒ Object
changes echo config
137 138 139 |
# File 'lib/ant/bot/adapters/debug.rb', line 137 def echo=(toogle) @channels.each { |_, channel| channel.echo = toogle } end |
#read_message ⇒ Object
Interface for receiving message
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ant/bot/adapters/debug.rb', line 96 def # take the first message from the first open message, # then rotate the array loop do raise NoMoreMessageException if @channels.values.all?(&:empty?) msg = @channels.values.find(&:open?) return msg. if msg # :nocov: # sleep(1) # :nocov: # end end |
#send_audio(channel_name, audio_url) ⇒ Object
interface for sending uadio
127 128 129 |
# File 'lib/ant/bot/adapters/debug.rb', line 127 def send_audio(channel_name, audio_url) channel(channel_name).answer("AUDIO: #{audio_url}") end |
#send_image(channel_name, image_url) ⇒ Object
interface for sending image
132 133 134 |
# File 'lib/ant/bot/adapters/debug.rb', line 132 def send_image(channel_name, image_url) channel(channel_name).answer("IMG: #{image_url}") end |
#send_message(channel_name, contents) ⇒ Object
interface for sending messages
117 118 119 |
# File 'lib/ant/bot/adapters/debug.rb', line 117 def (channel_name, contents) channel(channel_name).answer(contents) end |
#send_video(channel_name, video_url) ⇒ Object
interface for sending video
122 123 124 |
# File 'lib/ant/bot/adapters/debug.rb', line 122 def send_video(channel_name, video_url) channel(channel_name).answer("VIDEO: #{video_url}") end |