Class: Brewby::CLI::Views::Application
- Inherits:
-
Object
- Object
- Brewby::CLI::Views::Application
- Defined in:
- lib/brewby/cli/views/application.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#step_view ⇒ Object
readonly
Returns the value of attribute step_view.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #brew_timer ⇒ Object
- #clear ⇒ Object
- #current_step_index ⇒ Object
- #handle_input ⇒ Object
-
#initialize(app) ⇒ Application
constructor
A new instance of Application.
- #load_parent_view ⇒ Object
- #load_step_view(step) ⇒ Object
- #render ⇒ Object
- #step_count ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/brewby/cli/views/application.rb', line 7 def app @app end |
#step_view ⇒ Object (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 |
#view ⇒ Object (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_timer ⇒ Object
25 26 27 |
# File 'lib/brewby/cli/views/application.rb', line 25 def brew_timer app.timer_for(app.elapsed.to_i) end |
#clear ⇒ Object
57 58 59 |
# File 'lib/brewby/cli/views/application.rb', line 57 def clear view.clear end |
#current_step_index ⇒ Object
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_input ⇒ Object
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_view ⇒ Object
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 |
#render ⇒ Object
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_count ⇒ Object
21 22 23 |
# File 'lib/brewby/cli/views/application.rb', line 21 def step_count app.steps.size end |