Class: Senkyoshi::Content

Inherits:
FileResource show all
Defined in:
lib/senkyoshi/models/content.rb

Direct Known Subclasses

Assignment, Attachment, ExternalUrl, Quiz, WikiPage

Constant Summary collapse

CONTENT_TYPES =
{
  "x-bb-asmt-test-link" => "Quiz",
  "x-bb-asmt-survey-link" => "Quiz",
  "x-bb-assignment" => "Assignment",
  "x-bbpi-selfpeer-type1" => "Assignment",
  "x-bb-document" => "WikiPage",
  "x-bb-file" => "Attachment",
  "x-bb-audio" => "Attachment",
  "x-bb-image" => "Attachment",
  "x-bb-video" => "Attachment",
  "x-bb-externallink" => "ExternalUrl",
  "x-bb-blankpage" => "WikiPage",
  "x-bb-lesson" => "WikiPage",
  "x-bb-folder" => "WikiPage",
  "x-bb-module-page" => "WikiPage",
  "x-bb-lesson-plan" => "WikiPage",
  "x-bb-syllabus" => "WikiPage",
}.freeze
MODULE_TYPES =
{
  "Senkyoshi::Attachment" => "Attachment",
  "Senkyoshi::Assignment" => "Assignment",
  "Senkyoshi::ExternalUrl" => "ExternalUrl",
  "Senkyoshi::WikiPage" => "WikiPage",
  "Senkyoshi::Quiz" => "Quizzes::Quiz",
}.freeze

Instance Attribute Summary collapse

Attributes inherited from FileResource

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileResource

#initialize

Methods inherited from Resource

#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, #matches_xid?, #strip_xid

Constructor Details

This class inherits a constructor from Senkyoshi::FileResource

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



33
34
35
# File 'lib/senkyoshi/models/content.rb', line 33

def body
  @body
end

#extendeddataObject (readonly)

Returns the value of attribute extendeddata.



34
35
36
# File 'lib/senkyoshi/models/content.rb', line 34

def extendeddata
  @extendeddata
end

#filesObject

Returns the value of attribute files.



33
34
35
# File 'lib/senkyoshi/models/content.rb', line 33

def files
  @files
end

#titleObject

Returns the value of attribute title.



33
34
35
# File 'lib/senkyoshi/models/content.rb', line 33

def title
  @title
end

#urlObject

Returns the value of attribute url.



33
34
35
# File 'lib/senkyoshi/models/content.rb', line 33

def url
  @url
end

Class Method Details

.from(xml, pre_data, resource_xids) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/senkyoshi/models/content.rb', line 36

def self.from(xml, pre_data, resource_xids)
  type = xml.xpath("/CONTENT/CONTENTHANDLER/@value").first.text
  type.slice! "resource/"

  xml.xpath("//FILES/FILE").each do |file|
    file_name = ContentFile.clean_xid file.at("NAME").text
    is_attachment = CONTENT_TYPES[type] == "Attachment"
    if !resource_xids.include?(file_name) && is_attachment
      type = "x-bb-document"
      break
    end
  end

  if content_type = CONTENT_TYPES[type]
    content_class = Senkyoshi.const_get content_type
    content_class.new(pre_data[:file_name]).iterate_xml(xml, pre_data)
  end
end

.get_pre_data(xml, file_name) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/senkyoshi/models/content.rb', line 85

def self.get_pre_data(xml, file_name)
  id = xml.xpath("/CONTENT/@id").first.text
  parent_id = xml.xpath("/CONTENT/PARENTID/@value").first.text
  {
    id: id,
    parent_id: parent_id,
    file_name: file_name,
  }
end

Instance Method Details

#canvas_conversion(course, _resources = nil) ⇒ Object



95
96
97
# File 'lib/senkyoshi/models/content.rb', line 95

def canvas_conversion(course, _resources = nil)
  course
end

#create_module(course) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/senkyoshi/models/content.rb', line 99

def create_module(course)
  course.canvas_modules ||= []
  cc_module = course.canvas_modules.
    detect { |a| a.identifier == @parent_id }
  if cc_module
    cc_module.module_items << @module_item
  else
    title = @parent_title || @title
    cc_module = Module.new(title, @parent_id)
    cc_module = cc_module.canvas_conversion
    cc_module.module_items << @module_item
    course.canvas_modules << cc_module
  end
  course
end

#iterate_xml(xml, pre_data) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/senkyoshi/models/content.rb', line 55

def iterate_xml(xml, pre_data)
  @points = pre_data[:points] || 0
  @parent_title = pre_data[:parent_title]
  @title = xml.xpath("/CONTENT/TITLE/@value").first.text
  @url = xml.at("URL")["value"]
  @body = xml.xpath("/CONTENT/BODY/TEXT").first.text
  @extendeddata = xml.at("/CONTENT/EXTENDEDDATA/ENTRY")
  if @extendeddata
    @extendeddata = @extendeddata.text
  end
  @type = xml.xpath("/CONTENT/RENDERTYPE/@value").first.text
  @parent_id = pre_data[:parent_id]
  @module_type = MODULE_TYPES[self.class.name]

  if pre_data[:assignment_id] && !pre_data[:assignment_id].empty?
    @id = pre_data[:assignment_id]
  end

  @files = xml.xpath("//FILES/FILE").map do |file|
    ContentFile.new(file)
  end
  @module_item = set_module if @module_type
  self
end

#set_moduleObject



80
81
82
83
# File 'lib/senkyoshi/models/content.rb', line 80

def set_module
  module_item = ModuleItem.new(@title, @module_type, @id, @url)
  module_item.canvas_conversion
end