Class: CF::TaskForm

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/task_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @form_fields =[]
  @station     = options[:station]
  @title       = options[:title]
  @instruction = options[:instruction]
  if !@station.nil?
    resp = self.class.post("/lines/#{CF.}/#{@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

#errorsObject

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

#instructionObject

instruction of the form



10
11
12
# File 'lib/cf/task_form.rb', line 10

def instruction
  @instruction
end

#stationObject

station attributes required to store station information



16
17
18
# File 'lib/cf/task_form.rb', line 16

def station
  @station
end

#titleObject

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(options, &block)
  form = TaskForm.new(options)
  if block.arity >= 1
    block.call(form)
  else
    form.instance_eval &block
  end
  form
end

Instance Method Details

#to_sObject

: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