Class: Pechkin::Chanel

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/channel.rb

Overview

Creates object which can send messages to assigned chanels

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connector, channel_list) ⇒ Chanel

Returns a new instance of Chanel.



6
7
8
9
10
11
# File 'lib/pechkin/channel.rb', line 6

def initialize(connector, channel_list)
  @connector = connector
  @channel_list = channel_list
  @channel_list = [channel_list] unless channel_list.is_a?(Array)
  @logger = ::Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



4
5
6
# File 'lib/pechkin/channel.rb', line 4

def logger
  @logger
end

Instance Method Details

#send_message(message, data, options) ⇒ Object



13
14
15
16
17
18
# File 'lib/pechkin/channel.rb', line 13

def send_message(message, data, options)
  text = Message.new(data).render(message)
  logger.warn 'Resulting text is empty' if text.empty?
  results = @channel_list.map { |id| @connector.send_message(id, text, options) }
  process_results(message, results)
end