Class: Csv2qti::Course

Inherits:
Object
  • Object
show all
Defined in:
lib/csv2qti/course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, file_path) ⇒ Course

Returns a new instance of Course.



7
8
9
10
11
# File 'lib/csv2qti/course.rb', line 7

def initialize(title, file_path)
  @title = title
  @file_path = file_path
  @primary_outcomes = []
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/csv2qti/course.rb', line 5

def file_path
  @file_path
end

#primary_outcomesObject (readonly)

Returns the value of attribute primary_outcomes.



5
6
7
# File 'lib/csv2qti/course.rb', line 5

def primary_outcomes
  @primary_outcomes
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/csv2qti/course.rb', line 5

def title
  @title
end

Instance Method Details

#add_primary_outcome(row) ⇒ Object



13
14
15
16
# File 'lib/csv2qti/course.rb', line 13

def add_primary_outcome(row)
  @primary_outcomes << Outcome.new(row)
  @primary_outcomes.last
end

#generate_cc(filename = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/csv2qti/course.rb', line 18

def generate_cc(filename=nil)
  filename ||= @title
  course = CanvasCc::CanvasCC::Models::Course.new
  course.title = @title
  course.identifier = rand(1000).to_s

  @primary_outcomes.each do |po|
    course.assessments << po.generate_assessment
  end

  dir = Dir.mktmpdir
  file = CanvasCc::CanvasCC::CartridgeCreator.new(course).create(dir)

  FileUtils.mv(file, "./#{filename.downcase.gsub(' ', '_')}.zip")
end

#to_sObject



34
35
36
# File 'lib/csv2qti/course.rb', line 34

def to_s
  @primary_outcomes.inject("#{title}\nOutcomes:") { |s, o| s + "\n" + o.to_s }
end