Class: Brewby::CLI::Views::TempControl

Inherits:
Object
  • Object
show all
Defined in:
lib/brewby/cli/views/temp_control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step, view) ⇒ TempControl

Returns a new instance of TempControl.



6
7
8
9
# File 'lib/brewby/cli/views/temp_control.rb', line 6

def initialize step, view
  @step = step
  @view = view
end

Instance Attribute Details

#stepObject (readonly)

Returns the value of attribute step.



5
6
7
# File 'lib/brewby/cli/views/temp_control.rb', line 5

def step
  @step
end

#viewObject (readonly)

Returns the value of attribute view.



5
6
7
# File 'lib/brewby/cli/views/temp_control.rb', line 5

def view
  @view
end

Instance Method Details

#handle_input(key) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/brewby/cli/views/temp_control.rb', line 54

def handle_input key
  case key
  when 'e'.ord
    if step.mode == :manual
      new_pct = [(step.power_level + 0.05).round(2), 1.0].min
      step.set_power_level new_pct
    end
  when 'c'.ord
    if step.mode == :manual
      new_pct = [(step.power_level - 0.05).round(2), 0.0].max
      step.set_power_level new_pct
    end
  end
end

#power_levelObject



11
12
13
# File 'lib/brewby/cli/views/temp_control.rb', line 11

def power_level
  (step.power_level * 100.0).round(3)
end

#renderObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/brewby/cli/views/temp_control.rb', line 23

def render
  view.move 2, 10
  if step.name
    view.addstr step.name.ljust(70)
  else
    view.addstr "#{step.mode.capitalize} Temp Control".ljust(70)
  end

  view.move 6, 0
  view.addstr "Power Level: #{power_level}%".ljust(70)
  view.move 16, 50
  view.addstr "Step Timer: #{timer}"
  view.refresh

  if step.target
    view.move 4, 0
    view.addstr "Target Temp: #{step.target} F".ljust(70)
  end

  view.move 5, 0
  view.addstr "Actual Temp: #{step.last_reading} F".ljust(25)

  if step.threshold_reached
    view.move 7, 0
    view.addstr "Time Remaining: #{time_remaining}".ljust(70)
  else
    view.move 7, 0
    view.addstr "".ljust(70)
  end
end

#time_remainingObject



19
20
21
# File 'lib/brewby/cli/views/temp_control.rb', line 19

def time_remaining
  step.countdown_for(step.time_remaining)
end

#timerObject



15
16
17
# File 'lib/brewby/cli/views/temp_control.rb', line 15

def timer
  step.timer_for(step.elapsed.to_i)
end