Class: Scheduler

Inherits:
Object
  • Object
show all
Defined in:
app/scheduler.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


33
34
35
# File 'app/scheduler.rb', line 33

def continue?
  @last_action == '' or last_action_was_resume?
end

#interrupt_kataObject



25
26
27
28
29
30
31
# File 'app/scheduler.rb', line 25

def interrupt_kata
  @view.show_kata_exit_message 
  @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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


45
46
47
# File 'app/scheduler.rb', line 45

def last_action_was_upload?
  @last_action.start_with? 'u'
end

#register_interrupt_listenerObject



19
20
21
22
23
# File 'app/scheduler.rb', line 19

def register_interrupt_listener
  trap("INT") {
    interrupt_kata
  }
end

#startObject



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