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",
  "x-bb-courselink" => "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, get_pre_data, #matches_xid?, #strip_xid

Constructor Details

This class inherits a constructor from Senkyoshi::FileResource

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



49
50
51
# File 'lib/senkyoshi/models/content.rb', line 49

def body
  @body
end

#extendeddataObject (readonly)

Returns the value of attribute extendeddata.



50
51
52
# File 'lib/senkyoshi/models/content.rb', line 50

def extendeddata
  @extendeddata
end

#filesObject

Returns the value of attribute files.



49
50
51
# File 'lib/senkyoshi/models/content.rb', line 49

def files
  @files
end

#titleObject

Returns the value of attribute title.



49
50
51
# File 'lib/senkyoshi/models/content.rb', line 49

def title
  @title
end

#urlObject

Returns the value of attribute url.



49
50
51
# File 'lib/senkyoshi/models/content.rb', line 49

def url
  @url
end

Class Method Details

.from(xml, pre_data, resource_xids) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/senkyoshi/models/content.rb', line 52

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

Instance Method Details

#canvas_conversion(course, _resources = nil) ⇒ Object



110
111
112
# File 'lib/senkyoshi/models/content.rb', line 110

def canvas_conversion(course, _resources = nil)
  course
end

#create_module(course) ⇒ Object



114
115
116
# File 'lib/senkyoshi/models/content.rb', line 114

def create_module(course)
  super(course)
end

#iterate_xml(xml, pre_data) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/senkyoshi/models/content.rb', line 71

def iterate_xml(xml, pre_data)
  @points = pre_data[:points] || 0
  @parent_title = pre_data[:parent_title]
  @indent = pre_data[:indent]
  @file_name = pre_data[:file_name]
  @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]
  @referred_to_title = pre_data[:referred_to_title]

  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



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

def set_module
  ModuleItem.new(
    @title,
    @module_type,
    @id,
    @url,
    @indent,
    @file_name,
  ).canvas_conversion
end