Class: CF::TaskForm
Instance Attribute Summary collapse
-
#errors ⇒ Object
Contains Error message if any.
-
#form_fields(form_fields = nil) ⇒ Object
Adding different form_fields ===Syntax for FormField method is form_fields << form_field_values ==Usage of form_fields method line = CF::Line.create(“Digitize Card”,“Digitization”) do |l| CF::InputHeader.new(=> l, :label => “Company”, :required => true, :valid_type => “general”) CF::InputHeader.new(=> l, :label => “Website”, :required => true, :valid_type => “url”) CF::Station.create(=> l, :type => “work”) do |s| CF::HumanWorker.new({:station => s, :number => 1, :reward => 20) CF::Form.create(:station => s, :title => “Enter text from a business card image”, :instruction => “Describe”) do |i| CF::FormField.new(=> i, :label => “First Name”, :field_type => “SA”, :required => “true”) CF::FormField.new(=> i, :label => “Middle Name”, :field_type => “SA”) CF::FormField.new(=> i, :label => “Last Name”, :field_type => “SA”, :required => “true”) end end end.
-
#instruction ⇒ Object
instruction of the form.
-
#station ⇒ Object
station attributes required to store station information.
-
#title ⇒ Object
title of the form.
Class Method Summary collapse
-
.create(options, &block) ⇒ Object
Initializes a new Form within block using Variable ===Usage Example: line = CF::Line.create(“Digitize Card”,“Digitization”) do |l| CF::InputHeader.new(=> l, :label => “Company”, :required => true, :valid_type => “general”) CF::InputHeader.new(=> l, :label => “Website”, :required => true, :valid_type => “url”) CF::Station.create(=> l, :type => “work”) do |s| CF::HumanWorker.new({:station => s, :number => 1, :reward => 20) CF::Form.create(:station => s, :title => “Enter text from a business card image”, :instruction => “Describe”) end end.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TaskForm
constructor
Initializes a new Form ===Usage Example: attrs = => “Enter text from a business card image”, :instruction => “Describe”.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ TaskForm
Initializes a new Form
Usage Example:
attrs = {:title => "Enter text from a business card image",
:instruction => "Describe"}
instruction = CF::Form.new(attrs)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cf/task_form.rb', line 27 def initialize(={}) @form_fields =[] @station = [:station] @title = [:title] @instruction = [:instruction] if !@station.nil? resp = self.class.post("/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/form.json", :form => {:title => @title, :instruction => @instruction, :_type => "TaskForm"}) resp.to_hash.each_pair do |k,v| self.send("#{k}=",v) if self.respond_to?(k) end self.errors = resp['error']['message'] if resp['code'] != 200 @station.form = self end end |
Instance Attribute Details
#errors ⇒ Object
Contains Error message if any
19 20 21 |
# File 'lib/cf/task_form.rb', line 19 def errors @errors end |
#form_fields(form_fields = nil) ⇒ Object
Adding different form_fields
Syntax for FormField method is form_fields << form_field_values
Usage of form_fields method
line = CF::Line.create("Digitize Card","Digitization") do |l|
CF::InputHeader.new({:line => l, :label => "Company", :required => true, :valid_type => "general"})
CF::InputHeader.new({:line => l, :label => "Website", :required => true, :valid_type => "url"})
CF::Station.create({:line => l, :type => "work") do |s|
CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
CF::FormField.new({:instruction => i, :label => "First Name", :field_type => "SA", :required => "true"})
CF::FormField.new({:instruction => i, :label => "Middle Name", :field_type => "SA"})
CF::FormField.new({:instruction => i, :label => "Last Name", :field_type => "SA", :required => "true"})
end
end
end
13 14 15 |
# File 'lib/cf/task_form.rb', line 13 def form_fields @form_fields end |
#instruction ⇒ Object
instruction of the form
10 11 12 |
# File 'lib/cf/task_form.rb', line 10 def instruction @instruction end |
#station ⇒ Object
station attributes required to store station information
16 17 18 |
# File 'lib/cf/task_form.rb', line 16 def station @station end |
#title ⇒ Object
title of the form
7 8 9 |
# File 'lib/cf/task_form.rb', line 7 def title @title end |
Class Method Details
.create(options, &block) ⇒ Object
Initializes a new Form within block using Variable
Usage Example:
line = CF::Line.create("Digitize Card","Digitization") do |l|
CF::InputHeader.new({:line => l, :label => "Company", :required => true, :valid_type => "general"})
CF::InputHeader.new({:line => l, :label => "Website", :required => true, :valid_type => "url"})
CF::Station.create({:line => l, :type => "work") do |s|
CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
CF::Form.create(:station => s, :title => "Enter text from a business card image", :instruction => "Describe"})
end
end
52 53 54 55 56 57 58 59 60 |
# File 'lib/cf/task_form.rb', line 52 def self.create(, &block) form = TaskForm.new() if block.arity >= 1 block.call(form) else form.instance_eval &block end form end |
Instance Method Details
#to_s ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/cf/task_form.rb', line 107 def to_s # :nodoc: "{:title => #{self.title}, :instruction => #{self.instruction}, :form_fields => #{self.form_fields}, :errors => #{self.errors}}" end |