Class: Step

Inherits:
Object
  • Object
show all
Defined in:
lib/tuvi/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, &block) ⇒ Step

Returns a new instance of Step.



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

def initialize(id, &block)
  @id = id
  @response_paths = {}
  @code_blocks = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#code_blocksObject

Returns the value of attribute code_blocks.



3
4
5
# File 'lib/tuvi/step.rb', line 3

def code_blocks
  @code_blocks
end

#exit_programObject

Returns the value of attribute exit_program.



3
4
5
# File 'lib/tuvi/step.rb', line 3

def exit_program
  @exit_program
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/tuvi/step.rb', line 3

def id
  @id
end

#response_pathsObject

Returns the value of attribute response_paths.



3
4
5
# File 'lib/tuvi/step.rb', line 3

def response_paths
  @response_paths
end

Instance Method Details

#code(&block) ⇒ Object



34
35
36
# File 'lib/tuvi/step.rb', line 34

def code(&block)
  code_blocks << block
end

#formatted_responsesObject



30
31
32
# File 'lib/tuvi/step.rb', line 30

def formatted_responses
  "Choose a command: [#{@response_paths.keys.join(", ")}]"
end

#get_sayObject



16
17
18
# File 'lib/tuvi/step.rb', line 16

def get_say
  @say
end

#response(response_path) ⇒ Object



20
21
22
23
24
# File 'lib/tuvi/step.rb', line 20

def response(response_path)
  response = response_path.first[0].downcase
  next_step = response_path.first[1]
  @response_paths[response] = next_step
end

#say(text) ⇒ Object



12
13
14
# File 'lib/tuvi/step.rb', line 12

def say(text)
  @say = text
end

#stopObject



26
27
28
# File 'lib/tuvi/step.rb', line 26

def stop
  @exit_program = true
end