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.
-
#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.
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 ⇒ 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.
-
#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
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cf/line.rb', line 38 def initialize(title, department_name, ={}) @input_formats =[] @stations =[] @title = title @department_name = department_name @public = [:public].present? ? [:public] : true @description = [:description] resp = self.class.post("/lines/#{CF.account_name}.json", {:line => {:title => title, :department_name => department_name, :public => @public, :description => @description}}) if resp.code != 200 self.errors = resp.error. end 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
20 21 22 |
# File 'lib/cf/line.rb', line 20 def description @description end |
#errors ⇒ Object
Contains Error Messages
29 30 31 |
# File 'lib/cf/line.rb', line 29 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
26 27 28 |
# File 'lib/cf/line.rb', line 26 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
32 33 34 |
# File 'lib/cf/line.rb', line 32 def output_formats @output_formats 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
23 24 25 |
# File 'lib/cf/line.rb', line 23 def stations @stations end |
#title ⇒ Object
Title of the Line
7 8 9 |
# File 'lib/cf/line.rb', line 7 def title @title end |
Class Method Details
.all(options = {}) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/cf/line.rb', line 259 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. 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 send_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
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/cf/line.rb', line 148 def self.create(title, department_name, ={}, &block) line = Line.new(title,department_name,={}) @public = [:public] @description = [:description] if block.arity >= 1 block.call(line) else line.instance_eval &block end line end |
.destroy(title, options = {}) ⇒ Object
327 328 329 330 331 332 333 334 335 336 |
# File 'lib/cf/line.rb', line 327 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. if resp.code != 200 return resp end |
.find(line) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/cf/line.rb', line 238 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 @errors = resp.error. if resp.code != 200 return resp.to_hash end |
.info(line) ⇒ Object
223 224 225 226 227 228 229 230 231 |
# File 'lib/cf/line.rb', line 223 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. if resp.code != 200 return resp end |
.inspect(line_title) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/cf/line.rb', line 341 def self.inspect(line_title) resp = get("/lines/#{CF.account_name}/#{line_title.downcase}/inspect.json") @errors = resp.error. 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 resp end end |
Instance Method Details
#destroy(options = {}) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/cf/line.rb', line 310 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 if resp.code != 200 self.errors = resp.errors. end return resp end |
#get_stations ⇒ Object
282 283 284 |
# File 'lib/cf/line.rb', line 282 def get_stations CF::Station.get("/lines/#{ACCOUNT_NAME}/#{self.title.downcase}/stations.json") end |
#update(options = {}) ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'lib/cf/line.rb', line 297 def update(={}) # :nodoc: old_title = self.title @title = [:title] @department_name = [:department_name] @public = [:public] @description = [:description] self.class.put("/lines/#{CF.account_name}/#{old_title.downcase}.json", :line => {:title => @title, :department_name => @department_name, :public => @public, :description => @description}) end |