Class: CF::RobotWorker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @type = options[:type].nil? ? nil : options[:type].camelize
  @settings = options[:settings]
  station = options[:station]
  
  if station
    request = options[:settings].merge(:type => @type)
    resp = self.class.post("/lines/#{CF.}/#{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

#errorsObject

Contains Error message if any



13
14
15
# File 'lib/cf/robot_worker.rb', line 13

def errors
  @errors
end

#numberObject

:nodoc:



18
19
20
# File 'lib/cf/robot_worker.rb', line 18

def number
  @number
end

#rewardObject

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

#settingsObject

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

#stationObject

Station attribute with which robot worker will be associated



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

def station
  @station
end

#typeObject

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(options)
  RobotWorker.new(options)
end

Instance Method Details

#to_sObject

: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