Class: Scheduler
- Inherits:
-
Object
- Object
- Scheduler
- Defined in:
- app/scheduler.rb
Instance Method Summary collapse
- #continue? ⇒ Boolean
-
#initialize(runner, view) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #interrupt_kata ⇒ Object
- #last_action_was_exit? ⇒ Boolean
- #last_action_was_resume? ⇒ Boolean
- #last_action_was_upload? ⇒ Boolean
- #register_interrupt_listener ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(runner, view) ⇒ Scheduler
Returns a new instance of Scheduler.
3 4 5 6 7 |
# File 'app/scheduler.rb', line 3 def initialize runner, view @runner = runner @view = view @last_action = "" end |
Instance Method Details
#continue? ⇒ Boolean
33 34 35 |
# File 'app/scheduler.rb', line 33 def continue? @last_action == '' or last_action_was_resume? end |
#interrupt_kata ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/scheduler.rb', line 25 def interrupt_kata @view. @last_action = @view.read_user_input.downcase if last_action_was_exit? then @view.show_kata_upload_hint end end |
#last_action_was_exit? ⇒ Boolean
41 42 43 |
# File 'app/scheduler.rb', line 41 def last_action_was_exit? @last_action.start_with? 'e' end |
#last_action_was_resume? ⇒ Boolean
37 38 39 |
# File 'app/scheduler.rb', line 37 def last_action_was_resume? @last_action.start_with? 'r' end |
#last_action_was_upload? ⇒ Boolean
45 46 47 |
# File 'app/scheduler.rb', line 45 def last_action_was_upload? @last_action.start_with? 'u' end |
#register_interrupt_listener ⇒ Object
19 20 21 22 23 |
# File 'app/scheduler.rb', line 19 def register_interrupt_listener trap("INT") { interrupt_kata } end |
#start ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/scheduler.rb', line 9 def start @last_action = "" register_interrupt_listener @runner.start while continue? do sleep 1 @runner.execute end end |