Class: CanvasSection

Inherits:
CanvasObject show all
Defined in:
lib/models/canvas_section.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CanvasObject

push_csv_to_canvas

Constructor Details

#initialize(opts = {}) ⇒ CanvasSection

Returns a new instance of CanvasSection.



9
10
11
12
13
14
15
# File 'lib/models/canvas_section.rb', line 9

def initialize(opts = {})
  @name = opts[:name] if opts[:name]
  @sis_id = opts[:sis_id] if opts[:sis_id]
  @course_id = opts[:course] if opts[:course]
  @start_date = opts[:start_at] if opts[:start_at]
  @end_date = opts[:end_at] if opts[:end_at]
end

Instance Attribute Details

#course_sis_idObject

Returns the value of attribute course_sis_id.



3
4
5
# File 'lib/models/canvas_section.rb', line 3

def course_sis_id
  @course_sis_id
end

#course_uidObject

Returns the value of attribute course_uid.



3
4
5
# File 'lib/models/canvas_section.rb', line 3

def course_uid
  @course_uid
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



2
3
4
# File 'lib/models/canvas_section.rb', line 2

def end_date
  @end_date
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/models/canvas_section.rb', line 2

def name
  @name
end

#sis_idObject (readonly)

Returns the value of attribute sis_id.



2
3
4
# File 'lib/models/canvas_section.rb', line 2

def sis_id
  @sis_id
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



2
3
4
# File 'lib/models/canvas_section.rb', line 2

def start_date
  @start_date
end

Class Method Details

.gen_file(opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/models/canvas_section.rb', line 30

def self.gen_file(opts = {})
  opts[:rows] ? rows = opts[:rows] : rows = 0
  sections = []
  if(opts[:rows])
    rows.times do |x|
      sections.push(CanvasSection.random)
    end
  end

  header = %w[section_id course_id name status integration_id start_date end_date]
  CSV.open('./sections.csv', 'wb', write_headers: true, headers: header) do |csv|
    sections.each do |acc|
      csv << acc.to_csv
    end
  end
  return sections
end

.random(course = 1) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/models/canvas_section.rb', line 17

def self.random(course=1)
  d = Forgery('date').date
  CanvasSection.new(
    {
      name: "#{Forgery('address').country} #{Forgery('basic').color}",
      sis_id: (21000+rand(1000000)),
      course: course,
      start_date: d,
      end_date: d+90.days
    }
  )
end

Instance Method Details

#to_csvObject



5
6
7
# File 'lib/models/canvas_section.rb', line 5

def to_csv
  row = [sis_id, course_sis_id, name, 'active', nil, start_date, end_date]
end