Class: Blinkman::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/blinkman/bot.rb

Constant Summary collapse

LED_COLORS =
{
  :red => {r: 255, g: 0, b: 0},
  :green => {r: 0, g: 255, b: 0},
  :blue => {r: 0, g: 0, b: 255},
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Bot

Returns a new instance of Bot.



14
15
16
17
18
19
20
# File 'lib/blinkman/bot.rb', line 14

def initialize(&block)
  Dotenv.load
  ::Bundler.require(:default)
  @adapter = Adapter.adapter_classes.last.new(self)
  @handlers = []
  instance_eval(&block) if block
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



12
13
14
# File 'lib/blinkman/bot.rb', line 12

def handlers
  @handlers
end

Instance Method Details

#listenObject



22
23
24
# File 'lib/blinkman/bot.rb', line 22

def listen
  @adapter.listen
end

#on_receive(message) ⇒ Object



26
27
28
29
# File 'lib/blinkman/bot.rb', line 26

def on_receive(message)
  selected_handler = handlers.find { |handler| handler.event.match?(message) }
  selected_handler.action.invoke if selected_handler
end