Class: VoiceForm::Form

Inherits:
Object
  • Object
show all
Includes:
FormMethods
Defined in:
lib/voice_form/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FormMethods

#field

Constructor Details

#initialize(options = {}, &block) ⇒ Form

Returns a new instance of Form.



9
10
11
12
13
14
15
16
# File 'lib/voice_form/form.rb', line 9

def initialize(options={}, &block)
  @options = options
  @form_stack = []
  @stack_index = 0

  instance_eval(&block)
  raise 'A form requires at least one field defined' if fields.empty?
end

Instance Attribute Details

#current_fieldObject (readonly)

Returns the value of attribute current_field.



7
8
9
# File 'lib/voice_form/form.rb', line 7

def current_field
  @current_field
end

#form_stackObject

Returns the value of attribute form_stack.



6
7
8
# File 'lib/voice_form/form.rb', line 6

def form_stack
  @form_stack
end

Instance Method Details

#do_block(&block) ⇒ Object



30
31
32
# File 'lib/voice_form/form.rb', line 30

def do_block(&block)
  form_stack << block
end

#exitObject



44
45
46
# File 'lib/voice_form/form.rb', line 44

def exit
  @exit = true
end

#goto(name) ⇒ Object



34
35
36
37
38
# File 'lib/voice_form/form.rb', line 34

def goto(name)
  index = field_index(name)
  raise "goto failed: No form field found with name '#{name}'." unless index
  @stack_index = index
end

#restartObject



40
41
42
# File 'lib/voice_form/form.rb', line 40

def restart
  @stack_index = 0
end

#run(component) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/voice_form/form.rb', line 18

def run(component)
  @component = component
  
  add_field_accessors
  run_setup
  run_form_stack
end

#setup(&block) ⇒ Object



26
27
28
# File 'lib/voice_form/form.rb', line 26

def setup(&block)
  @setup = block
end