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”).
-
#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 ⇒ Object
Returns all the lines of an account ===Syntax for all method is CF::Line.all.
-
.create(title, department_name, options = {}, &block) ⇒ Object
Initializes a new line ===Usage Example:.
-
.destroy(title) ⇒ 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”).
-
.public_lines ⇒ Object
Return all the public lines ===Usage Example: CF::Line.public_lines.
Instance Method Summary collapse
-
#destroy ⇒ 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
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cf/line.rb', line 35 def initialize(title, department_name, ={}) @input_formats =[] @stations =[] @title = title @department_name = department_name @public = [:public].present? ? [:public] : false @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 |
#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 ⇒ Object
193 194 195 |
# File 'lib/cf/line.rb', line 193 def self.all get("/lines/#{CF.account_name}.json") 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
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cf/line.rb', line 121 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) ⇒ Object
236 237 238 |
# File 'lib/cf/line.rb', line 236 def self.destroy(title) delete("/lines/#{CF.account_name}/#{title.downcase}.json") end |
.find(line) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/cf/line.rb', line 182 def self.find(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 end |
.info(line) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/cf/line.rb', line 169 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 end |
Instance Method Details
#destroy ⇒ Object
228 229 230 |
# File 'lib/cf/line.rb', line 228 def destroy self.class.delete("/lines/#{CF.account_name}/#{self.title.downcase}.json") end |
#get_stations ⇒ Object
200 201 202 |
# File 'lib/cf/line.rb', line 200 def get_stations CF::Station.get("/lines/#{ACCOUNT_NAME}/#{self.title.downcase}/stations.json") end |
#update(options = {}) ⇒ Object
215 216 217 218 219 220 221 222 |
# File 'lib/cf/line.rb', line 215 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 |