Class: Moodle2CC::CC::WebLink

Inherits:
Object
  • Object
show all
Includes:
CCHelper, Resource
Defined in:
lib/moodle2cc/cc/web_link.rb

Direct Known Subclasses

Moodle2CC::Canvas::WebLink

Constant Summary

Constants included from CCHelper

CCHelper::ASSESSMENT_CC_QTI, CCHelper::ASSESSMENT_META, CCHelper::ASSESSMENT_NON_CC_FOLDER, CCHelper::ASSESSMENT_TYPE, CCHelper::ASSIGNMENT_GROUPS, CCHelper::ASSIGNMENT_SETTINGS, CCHelper::BASIC_LTI, CCHelper::BLTI_NAMESPACE, CCHelper::CANVAS_NAMESPACE, CCHelper::CANVAS_PLATFORM, CCHelper::CC_ASSIGNMENT_FOLDER, CCHelper::CC_EXTENSION, CCHelper::CC_WIKI_FOLDER, CCHelper::COURSE_SETTINGS, CCHelper::COURSE_SETTINGS_DIR, CCHelper::COURSE_TOKEN, CCHelper::DISCUSSION_TOPIC, CCHelper::EVENTS, CCHelper::EXTERNAL_FEEDS, CCHelper::EXTERNAL_TOOLS, CCHelper::FILES_META, CCHelper::GRADING_STANDARDS, CCHelper::IMS_DATE, CCHelper::IMS_DATETIME, CCHelper::LEARNING_OUTCOMES, CCHelper::LOR, CCHelper::MANIFEST, CCHelper::MEDIA_OBJECTS_FOLDER, CCHelper::MODULE_META, CCHelper::MOODLE_FILEBASE_TOKEN, CCHelper::MOODLE_SLASH_TOKEN, CCHelper::OBJECT_TOKEN, CCHelper::QTI_ASSESSMENT_TYPE, CCHelper::QTI_EXTENSION, CCHelper::QUESTION_BANK, CCHelper::RUBRICS, CCHelper::SYLLABUS, CCHelper::WEBCONTENT, CCHelper::WEB_CONTENT_TOKEN, CCHelper::WEB_LINK, CCHelper::WEB_RESOURCES_FOLDER, CCHelper::WIKI_FOLDER, CCHelper::WIKI_TOKEN, CCHelper::XSD_URI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#create_organization_item_node, included

Methods included from CCHelper

convert_file_path_tokens, #convert_file_path_tokens, create_key, #create_key, create_mod_key, #create_mod_key, #create_resource_key, file_query_string, #file_slug, file_slug, #get_html_title_and_body, #get_html_title_and_body_and_id, #get_html_title_and_body_and_meta_fields, ims_date, #ims_date, ims_datetime, #ims_datetime, media_object_info

Constructor Details

#initialize(mod) ⇒ WebLink

Returns a new instance of WebLink.



8
9
10
11
12
13
14
# File 'lib/moodle2cc/cc/web_link.rb', line 8

def initialize(mod)
  super
  @url = mod.reference.to_s.strip
  @external_link = self.class.external_link?(mod)
  @href = @external_link ? "#{@identifier}.xml" : File.join(WEB_RESOURCES_FOLDER, @url)
  @identifier = create_key(@href, 'resource_') unless @external_link
end

Instance Attribute Details

Returns the value of attribute external_link.



6
7
8
# File 'lib/moodle2cc/cc/web_link.rb', line 6

def external_link
  @external_link
end

#hrefObject

Returns the value of attribute href.



6
7
8
# File 'lib/moodle2cc/cc/web_link.rb', line 6

def href
  @href
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/moodle2cc/cc/web_link.rb', line 6

def url
  @url
end

Class Method Details

.create_resource_key(mod) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/moodle2cc/cc/web_link.rb', line 16

def self.create_resource_key(mod)
  unless external_link?(mod)
    create_key(File.join(WEB_RESOURCES_FOLDER, mod.reference), 'resource_')
  else
    super
  end
end

.external_link?(mod) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/moodle2cc/cc/web_link.rb', line 24

def self.external_link?(mod)
  begin
    !!URI.parse(mod.reference.to_s.strip.gsub(/\s/, '+')).scheme
  rescue URI::InvalidURIError
    !!mod.reference.strip.match(/^https?\:\/\//)
  end
end

Instance Method Details

#create_files(export_dir) ⇒ Object



51
52
53
# File 'lib/moodle2cc/cc/web_link.rb', line 51

def create_files(export_dir)
  create_xml(export_dir)
end

#create_resource_node(resources_node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/moodle2cc/cc/web_link.rb', line 32

def create_resource_node(resources_node)
  if @external_link
    resources_node.resource(
      :type => WEB_LINK,
      :identifier => identifier
    ) do |resource_node|
      resource_node.file(:href => href)
    end
  else
    resources_node.resource(
      :type => WEBCONTENT,
      :href => href,
      :identifier => identifier
    ) do |resource_node|
      resource_node.file(:href => href)
    end
  end
end

#create_xml(export_dir) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/moodle2cc/cc/web_link.rb', line 55

def create_xml(export_dir)
  return unless @external_link
  path = File.join(export_dir, "#{identifier}.xml")
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    settings_node = Builder::XmlMarkup.new(:target => file, :indent => 2)
    settings_node.instruct!
    settings_node.webLink(
      :identifier => identifier,
      'xsi:schemaLocation' => "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd",
      'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
      'xmlns' => "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1"
    ) do |web_link_node|
      web_link_node.title @title
      web_link_node.url(:href => @url)
    end
  end
end