Class: CF::Line
Instance Attribute Summary collapse
-
#department_name ⇒ Object
Department Name for Line.
-
#description ⇒ Object
Description attribute describes about the line.
-
#errors ⇒ Object
Contains Error Messages.
-
#input_formats(input_formats_value = nil) ⇒ Object
Adds input format in a line ===Usage Example: line = Line.new(“line name”, “Survey”).
-
#output_formats(output_format = nil) ⇒ Object
Specifies output format for a line ===Usage Example: output_format = CF::OutputFormat.new(=> [{:name => “First Name”],:station_2 => [=> “Mobile”, :except => true]}) line.output_formats output_format.
-
#prefetch_task ⇒ Object
prefetch task is a boolean value.
-
#priority ⇒ Object
Priority is a integer attribute Higher the value of Priority field higher will be its precedence over other tasks which are shown to worker who are eligible for them Priority attribute is optional.
-
#public ⇒ Object
Public is a boolean attribute which when set to true becomes public & vice-versa.
-
#stations(stations = nil) ⇒ Object
Adds station in a line ===Usage Example: line = CF::Line.new(“line_name”, “Department_name”) station = CF::Station.new(=> “Work”) line.stations station.
-
#title ⇒ Object
Title of the Line.
-
#worker_pool ⇒ Object
worker_pool attribute is optional, by default it’s cloudfactory.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Returns all the lines of an account ===Syntax for all method is CF::Line.all OR CF:Line.all(:page => 1).
-
.create(title, department_name, options = {}, &block) ⇒ Object
Initializes a new line ===Usage Example:.
-
.destroy(title, options = {}) ⇒ Object
Deletes a line by passing it’s title ===Usage Example: line = CF::Line.new(“line_title”, “Survey”) CF::Line.destroy(“line_title”).
-
.find(line) ⇒ Object
Finds a line ===Usage Example: CF::Line.find(line) ==OR CF::Line.find(“line_title”).
-
.info(line) ⇒ Object
Returns the content of a line by making an Api call ===Usage Example: CF::Line.info(line) ==OR CF::Line.info(“line_title”).
-
.inspect(line_title) ⇒ Object
Return all the associated elements of a line ===Usage Example: line = CF::Line.inspect(“line_title”).
-
.public_lines(options = {}) ⇒ Object
Return all the public lines ===Usage Example: CF::Line.public_lines.
Instance Method Summary collapse
-
#destroy(options = {}) ⇒ Object
Deletes a line ===Usage Example: line = CF::Line.new(“Digitize Card”, “Survey”) line.destroy.
-
#get_stations ⇒ Object
Returns all the stations of a line ===Usage Example: CF::Line.get_stations.
-
#gold_standards(gold_standard = nil) ⇒ Object
specify the goldstandards for the line ===Usage Example: CF::GoldStandard.new({ :line => line,:name => “easy”, :input => [=>“”],:expected_output => [=> {“value” => “John”, “last_name” => => “Lennon”, “company” => => “Sprout”}]}).
-
#gold_standards=(gold_standard) ⇒ Object
:nodoc:.
-
#initialize(title, department_name, options = {}) ⇒ Line
constructor
Initializes a new line ==Usage of line.new(“line_name”).
-
#update(options = {}) ⇒ Object
Updates a line ===Syntax for update method is line = CF::Line.new(“Digitize Card”, “Survey”) line.update(=> “New Title”) * This changes the title of the “line” object from “Digitize Card” to “New Title”.
Constructor Details
#initialize(title, department_name, options = {}) ⇒ Line
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cf/line.rb', line 50 def initialize(title, department_name, ={}) @input_formats =[] @stations =[] @gold_standards = [] @title = title @department_name = department_name @public = [:public].nil? ? true : [:public] @priority = [:priority] @worker_pool = [:worker_pool].nil? ? "mturk" : [:worker_pool] @description = [:description] @prefetch_task = [:prefetch_task] == true ? true : false resp = self.class.post("/lines/#{CF.account_name}.json", {:line => {:title => title, :department_name => department_name, :public => @public, :priority => @priority, :worker_pool => @worker_pool, :description => @description, :prefetch_task => @prefetch_task}}) self.errors = resp['error']['message'] if resp['code'] != 200 return resp end |
Instance Attribute Details
#department_name ⇒ Object
Department Name for Line
10 11 12 |
# File 'lib/cf/line.rb', line 10 def department_name @department_name end |
#description ⇒ Object
Description attribute describes about the line
Description attribute is optional
29 30 31 |
# File 'lib/cf/line.rb', line 29 def description @description end |
#errors ⇒ Object
Contains Error Messages
41 42 43 |
# File 'lib/cf/line.rb', line 41 def errors @errors end |
#input_formats(input_formats_value = nil) ⇒ Object
Adds input format in a line
Usage Example:
line = Line.new("line name", "Survey")
input_format = CF::InputFormat.new({:label => "image_url", :required => true, :valid_type => "url"})
line.input_formats input_format
-
returns
line.input_formats as an array of input_formats
38 39 40 |
# File 'lib/cf/line.rb', line 38 def input_formats @input_formats end |
#output_formats(output_format = nil) ⇒ Object
Specifies output format for a line
Usage Example:
output_format = CF::OutputFormat.new({:station_1 => [{:name => "First Name"}],:station_2 => [{:name => "Mobile", :except => true}]})
line.output_formats output_format
44 45 46 |
# File 'lib/cf/line.rb', line 44 def output_formats @output_formats end |
#prefetch_task ⇒ Object
prefetch task is a boolean value. By default it is false.
32 33 34 |
# File 'lib/cf/line.rb', line 32 def prefetch_task @prefetch_task end |
#priority ⇒ Object
Priority is a integer attribute Higher the value of Priority field higher will be its precedence over other tasks which are shown to worker who are eligible for them Priority attribute is optional
20 21 22 |
# File 'lib/cf/line.rb', line 20 def priority @priority end |
#public ⇒ Object
Public is a boolean attribute which when set to true becomes public & vice-versa
Public attribute is optional, by default it’s true
15 16 17 |
# File 'lib/cf/line.rb', line 15 def public @public end |
#stations(stations = nil) ⇒ Object
35 36 37 |
# File 'lib/cf/line.rb', line 35 def stations @stations end |
#title ⇒ Object
Title of the Line
7 8 9 |
# File 'lib/cf/line.rb', line 7 def title @title end |
#worker_pool ⇒ Object
worker_pool attribute is optional, by default it’s cloudfactory
23 24 25 |
# File 'lib/cf/line.rb', line 23 def worker_pool @worker_pool end |
Class Method Details
.all(options = {}) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/cf/line.rb', line 345 def self.all(={}) page = [:page].presence if page resp = get("/lines/#{CF.account_name}.json", :page => page) else resp = get("/lines/#{CF.account_name}.json") end @errors = resp['error']['message'] if resp['code'] != 200 # new_resp = [] # if resp['lines'] # if resp['lines'].count > 0 # resp['lines'].each do |l| # new_resp << l.to_hash # end # end # end # send_resp = {"lines" => new_resp, "total_pages" => resp.total_pages, "total_lines" => resp.total_lines} return resp end |
.create(title, department_name, options = {}, &block) ⇒ Object
Initializes a new line
Usage Example:
creating Line within block using variable
Line.create("line_name", "Department_name") do |line|
CF::InputFormat.new({:line => line, :label => "image_url", :required => true, :valid_type => "url"})
CF::Station.new({:line => line, :type => "Work"})
end
OR
creating without variable
CF::Line.create("line_name", "Department_name") do
CF::InputFormat.new({:line => self, :label => "image_url", :required => true, :valid_type => "url"})
CF::Station.new({:line => self, :type => "Work"})
end
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/cf/line.rb', line 176 def self.create(title, department_name, ={}, &block) line = Line.new(title,department_name,) @public = [:public] @priority = [:priority] @worker_pool = [:worker_pool] @description = [:description] @prefetch_task = [:prefetch_task] == true ? true : false if block.arity >= 1 block.call(line) else line.instance_eval &block end line end |
.destroy(title, options = {}) ⇒ Object
419 420 421 422 423 424 425 426 427 428 |
# File 'lib/cf/line.rb', line 419 def self.destroy(title, ={}) forced = [:forced] if forced resp = delete("/lines/#{CF.account_name}/#{title.downcase}.json", {:forced => forced}) else resp = delete("/lines/#{CF.account_name}/#{title.downcase}.json") end @errors = resp['error']['message'] if resp['code'] != 200 return resp end |
.find(line) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/cf/line.rb', line 320 def self.find(line) if line.class == CF::Line resp = get("/lines/#{CF.account_name}/#{line.title.downcase}.json") elsif line.class == String if line.split("/").count == 2 account = line.split("/").first title = line.split("/").last resp = get("/lines/#{account}/#{title.downcase}.json") elsif line.split("/").count == 1 resp = get("/lines/#{CF.account_name}/#{line.downcase}.json") end end if resp['code'] != 200 @errors = resp['error']['message'] return nil else return resp end end |
.info(line) ⇒ Object
305 306 307 308 309 310 311 312 313 |
# File 'lib/cf/line.rb', line 305 def self.info(line) if line.class == CF::Line resp = get("/lines/#{CF.account_name}/#{line.title.downcase}.json") else resp = get("/lines/#{CF.account_name}/#{line.downcase}.json") end @errors = resp['error']['message'] if resp['code'] != 200 return resp end |
.inspect(line_title) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/cf/line.rb', line 433 def self.inspect(line_title) resp = get("/lines/#{CF.account_name}/#{line_title.downcase}/inspect.json") @errors = resp['error']['message'] if resp['code'] != 200 # if resp['code'] == 200 # send_resp = resp.to_hash # # @line_input_formats = [] # # resp.input_formats.each do |l_i| # # @line_input_formats << l_i.to_hash # # end # # send_resp.delete("input_formats") # # send_resp.merge!("input_formats" => @line_input_formats) # # @stations = [] # # # resp.stations.each do |s| # # @station_input_formats = [] # # s.input_formats.each do |i| # # @station_input_formats << i.to_hash # # end # # @station_form_fields = [] # # @temp_station = s.to_hash # # if !s.form_fields.nil? # # s.form_fields.each do |f| # # @station_form_fields << f.to_hash # # end # # @temp_station.delete("form_fields") # # @temp_station.merge!("form_fields" => @station_form_fields) # # end # # @temp_station.delete("input_formats") # # @temp_station.merge!("input_formats" => @station_input_formats) # # @stations << @temp_station # # end # # # # send_resp.delete("stations") # # send_resp.merge!("stations" => @stations) # send_resp # else return resp # end end |
.public_lines(options = {}) ⇒ Object
374 375 376 377 378 379 380 381 |
# File 'lib/cf/line.rb', line 374 def self.public_lines(={}) if [:page]=="all" resp = get("/public_lines.json", :page => "all") else resp = get("/public_lines.json") end return resp['lines'] end |
Instance Method Details
#destroy(options = {}) ⇒ Object
404 405 406 407 408 409 410 411 412 413 |
# File 'lib/cf/line.rb', line 404 def destroy(={}) force = [:force] if !force.nil? resp = self.class.delete("/lines/#{CF.account_name}/#{self.title.downcase}.json", :forced => force) else resp = self.class.delete("/lines/#{CF.account_name}/#{self.title.downcase}.json") end self.errors = resp['error']['message'] if resp['code'] != 200 return resp end |
#get_stations ⇒ Object
368 369 370 |
# File 'lib/cf/line.rb', line 368 def get_stations CF::Station.get("/lines/#{ACCOUNT_NAME}/#{self.title.downcase}/stations.json") end |
#gold_standards(gold_standard = nil) ⇒ Object
specify the goldstandards for the line
Usage Example:
CF::GoldStandard.new({ :line => line,:name => “easy”, :input => [=>“”],:expected_output => [=> {“value” => “John”, “last_name” => => “Lennon”, “company” => => “Sprout”}]})
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/cf/line.rb', line 256 def gold_standards gold_standard = nil if gold_standard line = self = gold_standard.settings if !.nil? # check whether the gold standard is from a file or not(check for bulk assignment of goldstandards) if [:file] puts [:file] if File.exist?([:file].to_s) file_upload = File.new([:file], 'rb') resp = self.class.post("/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json", {:file => file_upload, :template => [:template]}) gold_standard = CF::GoldStandard.new() resp.each do |gs| gold_standard.settings.merge!(gs.to_hash) end end else request = { :body => { :api_key => CF.api_key, :gold_standard => } } resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json",request) gold_standard = CF::GoldStandard.new() resp.parsed_response.first.delete("id") gold_standard.settings.merge!(resp.parsed_response.first.symbolize_keys) self.errors = resp.parsed_response['error']['message'] if resp.code != 200 end @gold_standards << gold_standard end else @gold_standards end end |
#gold_standards=(gold_standard) ⇒ Object
:nodoc:
295 296 297 |
# File 'lib/cf/line.rb', line 295 def gold_standards=(gold_standard) # :nodoc: @gold_standards << gold_standard end |
#update(options = {}) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/cf/line.rb', line 388 def update(={}) # :nodoc: old_title = self.title @title = [:title] @department_name = [:department_name] @public = [:public] @priority = [:priority] @worker_pool = [:worker_pool] @description = [:description] @prefetch_task = [:prefetch_task] == true ? true : false self.class.put("/lines/#{CF.account_name}/#{old_title.downcase}.json", :line => {:title => @title, :department_name => @department_name, :public => @public, :priority => @priority, :worker_pool => @worker_pool, :description => @description, :prefetch_task => @prefetch_task}) end |