Class: Hardware::Simulator
- Inherits:
-
Object
- Object
- Hardware::Simulator
- Defined in:
- lib/hardware/simulator.rb
Instance Attribute Summary collapse
-
#bin ⇒ Object
readonly
Returns the value of attribute bin.
-
#cash_register ⇒ Object
readonly
Returns the value of attribute cash_register.
-
#display ⇒ Object
readonly
Returns the value of attribute display.
Instance Method Summary collapse
- #assemble_hardware ⇒ Object
- #assemble_hardware_component(component_name, component) ⇒ Object
- #assemble_hardware_components(basename, components) ⇒ Object
- #boot ⇒ Object
- #button(no) ⇒ Object
- #component(component_name) ⇒ Object
- #drawer(no) ⇒ Object
-
#initialize(actuators = Adapter.actuators, sensors = Adapter.sensors) ⇒ Simulator
constructor
A new instance of Simulator.
- #monitor_changes(component_name, &block) ⇒ Object
- #on_boot(&block) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(actuators = Adapter.actuators, sensors = Adapter.sensors) ⇒ Simulator
Returns a new instance of Simulator.
6 7 8 9 10 |
# File 'lib/hardware/simulator.rb', line 6 def initialize(actuators = Adapter.actuators, sensors = Adapter.sensors) @components = {} @actuators = actuators @sensors = sensors end |
Instance Attribute Details
#bin ⇒ Object (readonly)
Returns the value of attribute bin.
4 5 6 |
# File 'lib/hardware/simulator.rb', line 4 def bin @bin end |
#cash_register ⇒ Object (readonly)
Returns the value of attribute cash_register.
4 5 6 |
# File 'lib/hardware/simulator.rb', line 4 def cash_register @cash_register end |
#display ⇒ Object (readonly)
Returns the value of attribute display.
4 5 6 |
# File 'lib/hardware/simulator.rb', line 4 def display @display end |
Instance Method Details
#assemble_hardware ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hardware/simulator.rb', line 31 def assemble_hardware assemble_hardware_component :bin, create_bin assemble_hardware_component :display, create_display assemble_hardware_component :cash_register, create_cash_register assemble_hardware_components :drawer, create_drawers assemble_hardware_components :button, end |
#assemble_hardware_component(component_name, component) ⇒ Object
16 17 18 19 |
# File 'lib/hardware/simulator.rb', line 16 def assemble_hardware_component(component_name, component) @components[component_name] = component component.configure end |
#assemble_hardware_components(basename, components) ⇒ Object
21 22 23 24 25 |
# File 'lib/hardware/simulator.rb', line 21 def assemble_hardware_components(basename, components) components.each_with_index do |component, sequence_number| assemble_hardware_component(component_name(basename, sequence_number), component) end end |
#boot ⇒ Object
53 54 55 |
# File 'lib/hardware/simulator.rb', line 53 def boot call_boot_block end |
#button(no) ⇒ Object
43 44 45 |
# File 'lib/hardware/simulator.rb', line 43 def (no) [no] end |
#component(component_name) ⇒ Object
12 13 14 |
# File 'lib/hardware/simulator.rb', line 12 def component(component_name) @components[component_name] end |
#drawer(no) ⇒ Object
39 40 41 |
# File 'lib/hardware/simulator.rb', line 39 def drawer(no) @drawers[no] end |
#monitor_changes(component_name, &block) ⇒ Object
27 28 29 |
# File 'lib/hardware/simulator.rb', line 27 def monitor_changes(component_name, &block) component(component_name).monitor_changes(&block) end |
#on_boot(&block) ⇒ Object
57 58 59 |
# File 'lib/hardware/simulator.rb', line 57 def on_boot(&block) @boot_block = block end |
#reset ⇒ Object
47 48 49 50 51 |
# File 'lib/hardware/simulator.rb', line 47 def reset @components.each { |name, component| component.reset } sensors.remove_fire_listeners boot end |