Class: Hardware::Drawer

Inherits:
SequencedComponent show all
Defined in:
lib/hardware/drawer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#monitor_changes

Constructor Details

#initialize(bin, sensor_collection = Adapter::SensorCollection.null, actuator_collection = Adapter::ActuatorCollection.null, sequence_number = 0) ⇒ Drawer

Returns a new instance of Drawer.



5
6
7
8
9
10
11
12
# File 'lib/hardware/drawer.rb', line 5

def initialize(bin, 
               sensor_collection = Adapter::SensorCollection.null, 
               actuator_collection = Adapter::ActuatorCollection.null, 
               sequence_number = 0)
  super(sensor_collection, actuator_collection, sequence_number)
  @bin = bin
  @stock = []
end

Instance Attribute Details

#stockObject (readonly)

Returns the value of attribute stock.



3
4
5
# File 'lib/hardware/drawer.rb', line 3

def stock
  @stock
end

Instance Method Details

#configureObject



29
30
31
32
33
34
35
# File 'lib/hardware/drawer.rb', line 29

def configure
  create_sensor_for(:drawer_drop_can)
  create_sensor_for(:drawer_fill_can)
  create_actuator_for(:drawer_drop_can) do
    self.drop
  end
end

#drop(time_it_takes = 3) ⇒ Object



22
23
24
25
26
27
# File 'lib/hardware/drawer.rb', line 22

def drop(time_it_takes = 3)
  return if @stock.empty?
  fire(:drawer_drop_can)
  sleep(time_it_takes)
  @bin.receive(@stock.shift)
end

#empty?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/hardware/drawer.rb', line 37

def empty?
  @stock.empty?
end

#fill(can_type, stock, time_it_takes_per_can = 1) ⇒ Object



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

def fill(can_type, stock, time_it_takes_per_can = 1)
  stock.times do
    @stock << can_type
    fire(:drawer_fill_can) 
  end
  self
end

#resetObject



41
42
43
# File 'lib/hardware/drawer.rb', line 41

def reset
  @stock.clear
end