class FormProcessor::Main
The gem's logic handler.
Attributes
result[R]
Result of the form submission after processing. Contains error String or nil if no errors.
Public Class Methods
new(values)
click to toggle source
Expects a Hash such as cgi.params
# File lib/formprocessor.rb, line 11 def initialize(values) @values = values @result = String.new @email_output = String.new setup run end
Private Instance Methods
run()
click to toggle source
# File lib/formprocessor.rb, line 26 def run if @values.has_key? 'required' then @result = Required.new(@values).result end if @values.has_key? 'mailto' and @result.length == 0 then Mailer.new(@values,@email_output) end if @values.has_key? 'redirect' and @result.length == 0 puts '<meta http-equiv="refresh" content="0;url=' + @values['redirect'] + '">' exit end if @result.length == 0 then @result = nil end end
setup()
click to toggle source
# File lib/formprocessor.rb, line 19 def setup @values.each do |key,val| if val.is_a? Array then temp = val.join(', '); val, @values[key] = temp, temp end temp = val.gsub(%r{</?[^>]+?>},'').strip; val, @values[key] = temp, temp @email_output += key.capitalize + ': ' + val + '<br />' end end