Class: Colloquy::Simulator

Inherits:
Object
  • Object
show all
Defined in:
lib/colloquy/simulator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Simulator

Returns a new instance of Simulator.



4
5
6
7
# File 'lib/colloquy/simulator.rb', line 4

def initialize(options = {})
  @renderer = Colloquy::Renderer.new(options)
  @renderer.prepare!
end

Instance Method Details

#ask_for_flow_parametersObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/colloquy/simulator.rb', line 39

def ask_for_flow_parameters
  puts 'Please enter flow name:'
  @flow_name = EM::Synchrony.gets.strip
  puts 'Please enter msisdn: '
  @msisdn = EM::Synchrony.gets.strip
  puts 'Please enter session_id: '
  @session_id = EM::Synchrony.gets.strip
  puts 'Initial input (for direct flow): '
  read_input
end

#construct_responseObject



9
10
11
# File 'lib/colloquy/simulator.rb', line 9

def construct_response 
  @renderer.apply(@flow_name, @msisdn, @session_id, @input)
end

#resetObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/colloquy/simulator.rb', line 27

def reset
  puts "\n--Going back to beginning of flow--\n"
  
  # Get a new session_id when the simulator is reset
  @session_id = @session_id.to_i + 1
  
  puts 'Initial input (for direct flow):'
  read_input
  
  run!
end

#runObject

Run simulator inside EM.synchrony loop



51
52
53
54
55
56
# File 'lib/colloquy/simulator.rb', line 51

def run
  EM.synchrony do
    ask_for_flow_parameters
    run!
  end
end

#run!Object



58
59
60
61
62
63
# File 'lib/colloquy/simulator.rb', line 58

def run!
  validate_request
  sanitize_parameters!
  
  run_simulator(@input)
end

#run_simulator(input) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/colloquy/simulator.rb', line 13

def run_simulator(input)
  response = construct_response
  puts response
  
  if response.flow_state == :notify
    puts "\n---Flow complete---"
    reset
  else
    read_input
  end
  
  run_simulator(@input)
end