require 'hardware_adapter' module Devices def self.method_missing(method_sym, *arguments, &block) devices = Devices.new devices.send(method_sym, *arguments, &block) end class Devices def initialize(actuators = Adapter.actuators, sensors = Adapter.sensors) @actuators = actuators @sensors = sensors end # display a a message on the specified line on the display # the line is a 0 based index in the available lines on the display def display_show(line, message) actuators.fire(:display_show, line, message) end # drops a coin in the bin where: # coin is 50 100 or 200 cts def cash_drop_coin(coin) actuators.fire(:"cash_drop_#{coin}") end # register a handler on filling coin of a specific # kind in the cash register def on_cash_filled(coin, &block) sensors.on(:"cash_fill_#{coin}", &block) end # register a handler on inserting a specifica coin # in the cash register as part of paying def on_cash_inserted(coin, &block) sensors.on(:"cash_insert_#{coin}", &block) end # register a handler on getting something being dropped in the bin def on_bin_entry(&block) sensors.on(:bin_entry, &block) end # register a handler on sbdy getting stuff from the bin def on_bin_fetch_all(&block) sensors.on(:bin_fetch_all, &block) end # register a handleer on sbgy pressing a specific button # where button can be one of 0 1 2 or three def on_button_pressed(button, &block) sensors.on(:"button_press_#{button}", &block) end # drops a can from a specified drawer def drawer_drop_can(drawer) actuators.fire(:"drawer_drop_can_#{drawer}") end # register a handler on a drawer dropping a can def on_drawer_dropped(drawer, &block) sensors.on(:"drawer_drop_can_#{drawer}", &block) end # register a handler on a drawer being filled with a can def on_drawer_filled(drawer, &block) sensors.on(:"drawer_fill_can_#{drawer}", &block) end private attr_reader :actuators, :sensors end end