Class: CanvasCourse
- Inherits:
-
CanvasObject
- Object
- Forgery
- CanvasObject
- CanvasCourse
- Defined in:
- lib/models/canvas_course.rb
Constant Summary collapse
- @@local_dictionaries =
$LOAD_PATH.grep(/bobross.*lib/).first
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sis_id ⇒ Object
readonly
Returns the value of attribute sis_id.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#term_id ⇒ Object
readonly
Returns the value of attribute term_id.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
- .course_code ⇒ Object
- .course_name ⇒ Object
- .description ⇒ Object
- .gen_file(opts = {}) ⇒ Object
- .random ⇒ Object
- .set_prefix(prefix) ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CanvasCourse
constructor
A new instance of CanvasCourse.
- #to_csv ⇒ Object
- #to_s ⇒ Object
Methods inherited from CanvasObject
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_id ⇒ Object (readonly)
Returns the value of attribute account_id.
2 3 4 |
# File 'lib/models/canvas_course.rb', line 2 def account_id @account_id end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
2 3 4 |
# File 'lib/models/canvas_course.rb', line 2 def description @description end |
#end_date ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/models/canvas_course.rb', line 2 def name @name end |
#sis_id ⇒ Object (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_date ⇒ Object (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_id ⇒ Object (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 |
#uid ⇒ Object (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_code ⇒ Object
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_name ⇒ Object
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 |
.description ⇒ Object
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 |
.random ⇒ Object
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_csv ⇒ Object
20 21 22 |
# File 'lib/models/canvas_course.rb', line 20 def to_csv row = [sis_id, uid, name, account_id, term_id, 'active', nil, start_date, end_date, 'online', nil] end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/models/canvas_course.rb', line 16 def to_s s = "#{name}, #{uid}, #{sis_id}, #{description}" end |