Class: CF::HumanWorker
- Inherits:
-
Object
- Object
- CF::HumanWorker
- Extended by:
- ActiveSupport::Concern
- Includes:
- Client
- Defined in:
- lib/cf/human_worker.rb
Instance Attribute Summary collapse
-
#badge ⇒ Object
Badge setting for “worker” object.
-
#errors ⇒ Object
Contains Error messages if any for “worker” object.
-
#id ⇒ Object
ID of “Worker” object.
-
#number ⇒ Object
Number of worker, e.g.
-
#reward ⇒ Object
Reward for worker, e.g.
-
#skill_badges ⇒ Object
Skill Badge for “worker” object example: badge_settings = { :title => ‘Football Fanatic’, :description => “This qualification allows you to perform work at stations which have this badge.”, :max_badges => 3, :test => { :input => => “Lionel Andres Messi”, :country => “Argentina”, :expected_output => [ => “Rosario, Santa Fe, Argentina”,:match_options => {:tolerance => 10, :ignore_case => true }, => “CF”,:match_options => {:tolerance => 1 }, => “Barcelona”,:match_options => {:tolerance => 1, :ignore_case => false } ] } }.
-
#stat_badge ⇒ Object
Stat Badge for “worker” object, e.g.
-
#station ⇒ Object
Station attribute for “worker” object.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HumanWorker
constructor
Initializes a new “worker” object ==Usage of HumanWorker.new(hash):.
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ HumanWorker
Initializes a new “worker” object
Usage of HumanWorker.new(hash):
In Block DSL way
line = CF::Line.create("human_worker", "Survey") do |l|
CF::Station.create({:line => l, :type => "work"}) do |s|
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
end
end
In Plain Ruby way
line = CF::Line.new("human_worker", "Digitization")
input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
line.input_formats input_format
station = CF::Station.new({:type => "work"})
line.stations station
worker = CF::HumanWorker.new({:number => 2, :reward => 20})
line.stations.first.worker = worker
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cf/human_worker.rb', line 71 def initialize(={}) @skill_badges = [] @station = [:station] @number = [:number].nil? ? 1 : [:number] @reward = [:reward] @badge = [:skill_badge].nil? ? nil : [:skill_badge] @stat_badge = [:stat_badge].nil? ? nil : [:stat_badge] if @station if [:skill_badge].nil? && [:stat_badge].nil? request = { :body => { :api_key => CF.api_key, :worker => {:number => @number, :reward => @reward, :type => "HumanWorker"} } } else request = { :body => { :api_key => CF.api_key, :worker => {:number => @number, :reward => @reward, :type => "HumanWorker"}, :skill_badge => @badge, :stat_badge => [:stat_badge] } } end resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers.json",request) self.id = resp.parsed_response['id'] self.number = resp.parsed_response['number'] self.reward = resp.parsed_response['reward'] self.stat_badge = resp.parsed_response['stat_badge'] @skill_badges << resp.parsed_response['skill_badges'] if resp.code != 200 self.errors = resp.parsed_response['error']['message'] end self.station = [:station] self.station.worker = self end end |
Instance Attribute Details
#badge ⇒ Object
Badge setting for “worker” object
48 49 50 |
# File 'lib/cf/human_worker.rb', line 48 def badge @badge end |
#errors ⇒ Object
Contains Error messages if any for “worker” object
45 46 47 |
# File 'lib/cf/human_worker.rb', line 45 def errors @errors end |
#id ⇒ Object
ID of “Worker” object
8 9 10 |
# File 'lib/cf/human_worker.rb', line 8 def id @id end |
#number ⇒ Object
Number of worker, e.g. :number => 3
11 12 13 |
# File 'lib/cf/human_worker.rb', line 11 def number @number end |
#reward ⇒ Object
Reward for worker, e.g. :reward => 10 (reward unit is in cents)
14 15 16 |
# File 'lib/cf/human_worker.rb', line 14 def reward @reward end |
#skill_badges ⇒ Object
Skill Badge for “worker” object example:
badge_settings =
{
:title => 'Football Fanatic',
:description => "This qualification allows you to perform work at stations which have this badge.",
:max_badges => 3,
:test =>
{
:input => {:name => "Lionel Andres Messi", :country => "Argentina"},
:expected_output =>
[
{:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},
{:position => "CF",:match_options => {:tolerance => 1 }},
{:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}
]
}
}
worker = CF::HumanWorker.new(=> 2, :reward => 20, :skill_badge => badge_settings)
42 43 44 |
# File 'lib/cf/human_worker.rb', line 42 def skill_badges @skill_badges end |
#stat_badge ⇒ Object
Stat Badge for “worker” object, e.g. worker = CF::HumanWorker.new(=> 2, :reward => 20, :stat_badge => {:approval_rating => 40, :assignment_duration => 1800, :abandonment_rate => 30})
20 21 22 |
# File 'lib/cf/human_worker.rb', line 20 def stat_badge @stat_badge end |
#station ⇒ Object
Station attribute for “worker” object
17 18 19 |
# File 'lib/cf/human_worker.rb', line 17 def station @station end |
Instance Method Details
#to_s ⇒ Object
159 160 161 |
# File 'lib/cf/human_worker.rb', line 159 def to_s "{:id => => #{self.id}, :number => #{self.number}, :reward => #{self.reward}, :stat_badge => #{self.stat_badge}, :skill_badges => #{self.skill_badges}, :errors => #{self.errors}}" end |