Class: CF::RobotWorker
- Inherits:
-
Object
- Object
- CF::RobotWorker
- Includes:
- Client
- Defined in:
- lib/cf/robot_worker.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Contains Error message if any.
-
#number ⇒ Object
:nodoc:.
-
#reward ⇒ Object
Reward for the Robot Worker; Every Robot Worker have their fixed Reward by default.
-
#settings ⇒ Object
settings for robot worker of the station, e.g.
-
#station ⇒ Object
Station attribute with which robot worker will be associated.
-
#type ⇒ Object
Type of robot worker.
Class Method Summary collapse
-
.create(options) ⇒ Object
Create a new Robot Worker ===Usage Example:.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RobotWorker
constructor
Initialize new Robot Worker ===Usage Example:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ RobotWorker
Initialize new Robot Worker
Usage Example:
In Block DSL way
line = CF::Line.create("sentiment_robot","Digitization") do |l|
CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
CF::Station.create({:line => l, :type => "work"}) do |s|
CF::RobotWorker.new({:station => s, :settings => {:document => "{url}", :sanitize => true}, :type => "sentiment_robot"})
end
end
OR
In Plain Ruby way
line = CF::Line.new("sentiment_robot_1","Digitization")
input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
line.input_formats input_format
station = CF::Station.new({:type => "work"})
line.stations station
worker = CF::RobotWorker.new({:settings => {:document => "{url}", :sanitize => true}, :type => "sentiment_robot"})
line.stations.first.worker = worker
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cf/robot_worker.rb', line 46 def initialize(={}) @type = [:type].nil? ? nil : [:type].camelize @settings = [:settings] station = [:station] if station request = [:settings].merge(:type => @type) resp = self.class.post("/lines/#{CF.account_name}/#{station.line_title.downcase}/stations/#{station.index}/workers.json", :worker => request) self.errors = resp['error']['message'] if resp['code'] != 200 self.number = resp['number'] self.reward = resp['reward'] self.station = station station.worker = self end end |
Instance Attribute Details
#errors ⇒ Object
Contains Error message if any
13 14 15 |
# File 'lib/cf/robot_worker.rb', line 13 def errors @errors end |
#number ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/cf/robot_worker.rb', line 18 def number @number end |
#reward ⇒ Object
Reward for the Robot Worker; Every Robot Worker have their fixed Reward by default
21 22 23 |
# File 'lib/cf/robot_worker.rb', line 21 def reward @reward end |
#settings ⇒ Object
settings for robot worker of the station, e.g. robot_worker = CF::RobotWorker.new(=> “sentiment_robot”, :settings => {:document => [“{url”], :sanitize => true}})
7 8 9 |
# File 'lib/cf/robot_worker.rb', line 7 def settings @settings end |
#station ⇒ Object
Station attribute with which robot worker will be associated
16 17 18 |
# File 'lib/cf/robot_worker.rb', line 16 def station @station end |
#type ⇒ Object
Type of robot worker
10 11 12 |
# File 'lib/cf/robot_worker.rb', line 10 def type @type end |
Class Method Details
.create(options) ⇒ Object
Create a new Robot Worker
Usage Example:
In Block DSL way
line = CF::Line.create("sentiment_robot","Digitization") do |l|
CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
CF::Station.create({:line => l, :type => "work"}) do |s|
CF::RobotWorker.create({:station => s, :settings => {:document => "{url}", :sanitize => true}, :type => "sentiment_robot"})
end
end
OR
In Plain Ruby way
line = CF::Line.new("sentiment_robot_1","Digitization")
input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
line.input_formats input_format
station = CF::Station.new({:type => "work"})
line.stations station
worker = CF::RobotWorker.create({:settings => {:document => "{url}", :sanitize => true}, :type => "sentiment_robot"})
line.stations.first.worker = worker
86 87 88 |
# File 'lib/cf/robot_worker.rb', line 86 def self.create() RobotWorker.new() end |
Instance Method Details
#to_s ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/cf/robot_worker.rb', line 90 def to_s # :nodoc: "{:number => #{self.number}, :reward => #{self.reward}, :type => #{self.type}, :settings => #{self.settings}, :errors => #{self.errors}}" end |