Class: MilkMaid::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/milk_maid/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Batch

Returns a new instance of Batch.



8
9
10
11
12
# File 'lib/milk_maid/batch.rb', line 8

def initialize(options = {})
  options.each { |key, value| send("#{key}=", value) }

  @batch_guid = generate_guid
end

Instance Attribute Details

#batch_guidObject

Returns the value of attribute batch_guid.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def batch_guid
  @batch_guid
end

#durationObject

Returns the value of attribute duration.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def duration
  @duration
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def name
  @name
end

#nap_timeObject

Returns the value of attribute nap_time.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def nap_time
  @nap_time
end

#notifierObject

Returns the value of attribute notifier.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def notifier
  @notifier
end

#sensorObject

Returns the value of attribute sensor.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def sensor
  @sensor
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def size
  @size
end

#temperatureObject

Returns the value of attribute temperature.



6
7
8
# File 'lib/milk_maid/batch.rb', line 6

def temperature
  @temperature
end

Instance Method Details

#compare_temperature(current_temperature) ⇒ Object



14
15
16
17
# File 'lib/milk_maid/batch.rb', line 14

def compare_temperature(current_temperature)
  notifier.log_temperature(current_temperature)
  current_temperature >= temperature
end

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/milk_maid/batch.rb', line 19

def start
  notifier.batch_started(name: name, guid: batch_guid, duration: duration, base_temperature: temperature, batch_size: size)

  until compare_temperature(sensor.reading)
    take_a_nap
  end

  ending_time = Time.now + duration

  notifier.temperature_reached

  until Time.now > ending_time
    current_temp = sensor.reading
    notifier.log_temperature(current_temp)

    notifier.post_warning(current_temp, temperature) if current_temp < temperature

    take_a_nap
  end

  # log final temperature
  current_temp = sensor.reading
  notifier.log_temperature(current_temp)

  notifier.batch_completed
end