Class: CF::Line

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, department_name, options = {}) ⇒ Line

Initializes a new line

Usage of line.new(“line_name”)

line = Line.new("line_name", "Survey")


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cf/line.rb', line 35

def initialize(title, department_name, options={})
  @input_formats =[]
  @stations =[]
  @title = title
  @department_name = department_name
  @public = options[:public].present? ? options[:public] : false
  @description = options[:description]
  resp = self.class.post("/lines/#{CF.}.json", {:line => {:title => title, :department_name => department_name, :public => @public, :description => @description}})
  if resp.code != 200
    self.errors = resp.error.message
  end
end

Instance Attribute Details

#department_nameObject

Department Name for Line



10
11
12
# File 'lib/cf/line.rb', line 10

def department_name
  @department_name
end

#descriptionObject

Description attribute describes about the line

Description attribute is optional



20
21
22
# File 'lib/cf/line.rb', line 20

def description
  @description
end

#errorsObject

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

#publicObject

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

Adds station in a line

Usage Example:

line = CF::Line.new("line_name", "Department_name")
station = CF::Station.new({:type => "Work"})
line.stations station
  • returns

line.stations as an array of stations



23
24
25
# File 'lib/cf/line.rb', line 23

def stations
  @stations
end

#titleObject

Title of the Line



7
8
9
# File 'lib/cf/line.rb', line 7

def title
  @title
end

Class Method Details

.allObject

Returns all the lines of an account

Syntax for all method is

CF::Line.all


193
194
195
# File 'lib/cf/line.rb', line 193

def self.all
  get("/lines/#{CF.}.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, options={}, &block)
  line = Line.new(title,department_name,options={})
  @public = options[:public]
  @description = options[:description]
  if block.arity >= 1
    block.call(line)
  else
    line.instance_eval &block
  end
  line
end

.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")


236
237
238
# File 'lib/cf/line.rb', line 236

def self.destroy(title)
  delete("/lines/#{CF.}/#{title.downcase}.json")
end

.find(line) ⇒ Object

Finds a line

Usage Example:

CF::Line.find(line)

OR

CF::Line.find("line_title")


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.}/#{line.title.downcase}.json")
  else
    resp = get("/lines/#{CF.}/#{line.downcase}.json")
  end
end

.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")


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.}/#{line.title.downcase}.json")
  else
    resp = get("/lines/#{CF.}/#{line.downcase}.json")
  end
end

.public_linesObject

Return all the public lines

Usage Example:

CF::Line.public_lines


206
207
208
# File 'lib/cf/line.rb', line 206

def self.public_lines
  get("/public_lines.json")
end

Instance Method Details

#destroyObject

Deletes a line

Usage Example:

line = CF::Line.new("Digitize Card", "Survey")
line.destroy


228
229
230
# File 'lib/cf/line.rb', line 228

def destroy
  self.class.delete("/lines/#{CF.}/#{self.title.downcase}.json")
end

#get_stationsObject

Returns all the stations of a line

Usage Example:

CF::Line.get_stations


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

Updates a line

Syntax for update method is

line = CF::Line.new("Digitize Card", "Survey")
line.update({:title => "New Title"})
  • This changes the title of the “line” object from “Digitize Card” to “New Title”



215
216
217
218
219
220
221
222
# File 'lib/cf/line.rb', line 215

def update(options={}) # :nodoc:
  old_title = self.title
  @title = options[:title]
  @department_name = options[:department_name]
  @public = options[:public]
  @description = options[:description]
  self.class.put("/lines/#{CF.}/#{old_title.downcase}.json", :line => {:title => @title, :department_name => @department_name, :public => @public, :description => @description})
end