Class: CanvasCourse

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

Constant Summary collapse

@@local_dictionaries =
$LOAD_PATH.grep(/bobross.*lib/).first

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CanvasObject

push_csv_to_canvas

Constructor Details

#initialize(opts = {}) ⇒ CanvasCourse

Returns a new instance of CanvasCourse.



5
6
7
8
9
10
11
12
13
14
# File 'lib/models/canvas_course.rb', line 5

def initialize(opts = {})
  @name = opts[:name] if opts[:name]
  @uid = opts[:uid] if opts[:uid]
  @sis_id = "#{opts[:sis]}" if opts[:sis]
  @description = opts[:desc] if opts[:desc]
  @account_id = opts[:account] if opts[:account]
  @term_id = opts[:term] if opts[:term]
  @start_date = opts[:start] if opts[:start]
  @end_date = opts[:end] if opts[:end]
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



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

def 
  @account_id
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



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

def end_date
  @end_date
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#sis_idObject (readonly)

Returns the value of attribute sis_id.



2
3
4
# File 'lib/models/canvas_course.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_course.rb', line 2

def start_date
  @start_date
end

#term_idObject (readonly)

Returns the value of attribute term_id.



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

def term_id
  @term_id
end

#uidObject (readonly)

Returns the value of attribute uid.



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

def uid
  @uid
end

Class Method Details

.course_codeObject



39
40
41
42
# File 'lib/models/canvas_course.rb', line 39

def self.course_code
  Forgery.load_from!(@@local_dictionaries)
  dictionaries[:course_codes][@@row]
end

.course_nameObject



44
45
46
47
48
49
# File 'lib/models/canvas_course.rb', line 44

def self.course_name
  Forgery.load_from!(@@local_dictionaries)
  name_count = Forgery.dictionaries[:course_names].count
  @@row = rand(name_count)
  dictionaries[:course_names][@@row]
end

.descriptionObject



51
52
53
# File 'lib/models/canvas_course.rb', line 51

def self.description
  Forgery(:lorem_ipsum).words(2+rand(30))
end

.gen_file(opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/models/canvas_course.rb', line 55

def self.gen_file(opts = {})
  opts[:rows] ? rows = opts[:rows] : rows = 0
  courses = []
  if(opts[:rows])
    rows.times do |x|
      courses.push(CanvasCourse.random)
    end
  end
  header = %w[course_id short_name long_name account_id term_id status integration_id start_date end_date course_format blueprint_course_id]
  CSV.open('./courses.csv', 'wb', write_headers: true, headers: header) do |csv|
    courses.each do |acc|
      csv << acc.to_csv
    end
  end
  return courses
end

.randomObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/models/canvas_course.rb', line 28

def self.random
  CanvasCourse.new(
    {
      name: CanvasCourse.course_name,
      uid: CanvasCourse.course_code,
      sis: (12_000+rand(1_000_000)).to_s,
      desc: CanvasCourse.description
    }
  )
end

.set_prefix(prefix) ⇒ Object



24
25
26
# File 'lib/models/canvas_course.rb', line 24

def self.set_prefix prefix
  @@prefix = prefix
end

Instance Method Details

#to_csvObject



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

def to_csv
  row = [sis_id, uid, name, , term_id, 'active', nil, start_date, end_date, 'online', nil]
end

#to_sObject



16
17
18
# File 'lib/models/canvas_course.rb', line 16

def to_s
  s = "#{name}, #{uid}, #{sis_id}, #{description}"
end