Class: BotMob::Roster

Inherits:
Object
  • Object
show all
Defined in:
lib/bot_mob/roster.rb

Overview

## BotMob::Roster

This manages the pool of bots made available by the application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoster

Returns a new instance of Roster.



9
10
11
# File 'lib/bot_mob/roster.rb', line 9

def initialize
  @bots = []
end

Instance Attribute Details

#botsObject (readonly)

Returns the value of attribute bots.



7
8
9
# File 'lib/bot_mob/roster.rb', line 7

def bots
  @bots
end

Instance Method Details

#disseminate(action, params = {}) ⇒ Object

## ‘disseminate`

This method will distribute a message or command to all bots on the roster. It collects and returns a compacted array of the bots’ responses



22
23
24
25
26
27
# File 'lib/bot_mob/roster.rb', line 22

def disseminate(action, params = {})
  bots.map do |bot|
    approach = "handle_#{action}".to_sym
    respond_to?(approach, true) ? send(approach, bot, params) : nil
  end.compact
end

#register(bot, **options) ⇒ Object



13
14
15
# File 'lib/bot_mob/roster.rb', line 13

def register(bot, **options)
  @bots << (bot.is_a?(Class) ? bot.new(options) : bot)
end