Class: Brewby::CLI::Views::Application

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Application

Returns a new instance of Application.



8
9
10
11
# File 'lib/brewby/cli/views/application.rb', line 8

def initialize app
  @app = app
  @view = load_parent_view
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#step_viewObject (readonly)

Returns the value of attribute step_view.



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

def step_view
  @step_view
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#brew_timerObject



25
26
27
# File 'lib/brewby/cli/views/application.rb', line 25

def brew_timer
  app.timer_for(app.elapsed.to_i)
end

#clearObject



57
58
59
# File 'lib/brewby/cli/views/application.rb', line 57

def clear
  view.clear
end

#current_step_indexObject



17
18
19
# File 'lib/brewby/cli/views/application.rb', line 17

def current_step_index
  app.steps.index(app.current_step)+1
end

#handle_inputObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/brewby/cli/views/application.rb', line 41

def handle_input
  if (char = view.getch) == 'q'[0].ord
    exit
  elsif char == 'n'[0].ord
    app.current_step.stop_timer
    app.ready = true
  else
    step_view.handle_input char
  end
end

#load_parent_viewObject



13
14
15
# File 'lib/brewby/cli/views/application.rb', line 13

def load_parent_view
  Brewby::CLI::View.new
end

#load_step_view(step) ⇒ Object



52
53
54
55
# File 'lib/brewby/cli/views/application.rb', line 52

def load_step_view step
  step_class_name = step.class.name.split("::").last
  @step_view = Brewby::CLI::Views.const_get(step_class_name).new step, view
end

#renderObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brewby/cli/views/application.rb', line 29

def render
  load_step_view app.current_step unless step_view
  view.move 1, 0
  view.addstr "BREWBY: Brewing '#{app.name}'" if app.name
  view.move 2, 0
  view.addstr "Step #{current_step_index}/#{step_count}: "
  view.move 16, 0
  view.addstr "Brew Timer: #{brew_timer}"
  view.refresh
  step_view.render
end

#step_countObject



21
22
23
# File 'lib/brewby/cli/views/application.rb', line 21

def step_count
  app.steps.size
end