Class: Campfire::Bot
- Inherits:
-
Object
- Object
- Campfire::Bot
- Defined in:
- lib/campfire_bot.rb,
lib/campfire_bot/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(message) ⇒ Object
-
#initialize(&block) ⇒ Bot
constructor
A new instance of Bot.
- #login(&block) ⇒ Object
- #on(regex, &block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(&block) ⇒ Bot
Returns a new instance of Bot.
12 13 14 15 16 |
# File 'lib/campfire_bot.rb', line 12 def initialize(&block) @events = [] block.call(self) if block_given? end |
Class Method Details
.config(&block) ⇒ Object
7 8 9 |
# File 'lib/campfire_bot.rb', line 7 def config(&block) new(&block) end |
Instance Method Details
#evaluate(message) ⇒ Object
36 37 38 39 40 |
# File 'lib/campfire_bot.rb', line 36 def evaluate() if event = find_event([:body]) event.action.call(@campfire, ) end end |
#login(&block) ⇒ Object
18 19 20 21 22 |
# File 'lib/campfire_bot.rb', line 18 def login(&block) config = Config.new block.call(config) @campfire = Tinder::Campfire.new(config.subdomain, login_credentials(config)).find_room_by_name(config.room) end |
#on(regex, &block) ⇒ Object
32 33 34 |
# File 'lib/campfire_bot.rb', line 32 def on(regex, &block) @events << Event.new(regex, block) end |
#start ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/campfire_bot.rb', line 24 def start raise "You need to configure me" unless @campfire @campfire.listen do |line| evaluate(line) if line[:body] end end |