Module: Tuvi

Defined in:
lib/tuvi.rb,
lib/tuvi/version.rb

Constant Summary collapse

VERSION =
"0.0.8"

Instance Method Summary collapse

Instance Method Details

#determine_next_step(current_step, input) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/tuvi.rb', line 32

def determine_next_step(current_step, input)
  if current_step.answer_paths[input]
    return current_step.answer_paths[input]
  end

  puts "Sorry, I don't understand that answer. Please try again:"
  current_step.position
end

#execute_step(step_position) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tuvi.rb', line 19

def execute_step(step_position)
  current_step = @steps[step_position]
  current_step.code_blocks.each do |block|
    block.call
  end
  puts current_step.get_message
  exit if current_step.exit_program
  puts current_step.formatted_answers
  input = gets.downcase.chomp
  exit_program if input == "exit"
  determine_next_step(current_step, input)
end

#exit_programObject



41
42
43
44
# File 'lib/tuvi.rb', line 41

def exit_program
  puts "Bye!"
  exit
end

#runObject



12
13
14
15
16
17
# File 'lib/tuvi.rb', line 12

def run
  current_step_position = 1
  while true do
    current_step_position = execute_step(current_step_position)
  end
end

#step(position, &block) ⇒ Object



7
8
9
10
# File 'lib/tuvi.rb', line 7

def step(position, &block)
  @steps ||= {}
  @steps[position] = Step.new(position, &block)
end