Class: Blinkman::Bot
- Inherits:
-
Object
- Object
- Blinkman::Bot
- 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
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Bot
constructor
A new instance of Bot.
- #listen ⇒ Object
- #on_receive(message) ⇒ Object
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
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
12 13 14 |
# File 'lib/blinkman/bot.rb', line 12 def handlers @handlers end |
Instance Method Details
#listen ⇒ Object
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() selected_handler = handlers.find { |handler| handler.event.match?() } selected_handler.action.invoke if selected_handler end |