Class: VoiceForm::Form
- Inherits:
-
Object
- Object
- VoiceForm::Form
- Includes:
- FormMethods
- Defined in:
- lib/voice_form/form.rb
Instance Attribute Summary collapse
-
#current_field ⇒ Object
readonly
Returns the value of attribute current_field.
-
#form_stack ⇒ Object
Returns the value of attribute form_stack.
Instance Method Summary collapse
- #do_block(&block) ⇒ Object
- #exit ⇒ Object
- #goto(name) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Form
constructor
A new instance of Form.
- #restart ⇒ Object
- #run(component) ⇒ Object
- #setup(&block) ⇒ Object
Methods included from FormMethods
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(={}, &block) = @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_field ⇒ Object (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_stack ⇒ Object
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 |
#exit ⇒ Object
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 |
#restart ⇒ Object
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 |