Module: Moodle2CC::Moodle2::Parsers::ParserHelper

Constant Summary collapse

FILES_XML =
'inforef.xml'
XML_NULL_VALUE =
'$@NULL@$'
MODULE_XML =
'module.xml'
MOODLE_FILEBASE_TOKEN =
'$@FILEPHP@$'
IMS_FILEBASE_TOKEN =
'$IMS_CC_FILEBASE$'
SLASH_TOKEN =
'$@SLASH@$'

Instance Method Summary collapse

Instance Method Details

#activity_directories(work_dir, activity_types) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/moodle2cc/moodle2/parsers/parser_helper.rb', line 12

def activity_directories(work_dir, activity_types)
  File.open(File.join(work_dir, Moodle2CC::Moodle2::Extractor::MOODLE_BACKUP_XML)) do |f|
    moodle_backup_xml = Nokogiri::XML(f)
    activities = moodle_backup_xml./('/moodle_backup/information/contents/activities').xpath("activity[modulename = '#{activity_types}']")
    activities.map { |forum| forum./('directory').text }
  end
end

#parse_boolean(node, xpath) ⇒ Object



28
29
30
31
# File 'lib/moodle2cc/moodle2/parsers/parser_helper.rb', line 28

def parse_boolean(node, xpath)
  value = parse_text(node, xpath)
  value && (value == '1' || value.downcase == 'true' || value.downcase == 'y') ? true : false
end

#parse_module(activity_dir, activity) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/moodle2cc/moodle2/parsers/parser_helper.rb', line 33

def parse_module(activity_dir, activity)
  File.open(File.join(activity_dir, MODULE_XML)) do |f|
    xml = Nokogiri::XML(f)
    activity.visible = parse_boolean(xml, '/module/visible')
  end
  activity
end

#parse_text(node, xpath, use_xpath = false) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/moodle2cc/moodle2/parsers/parser_helper.rb', line 20

def parse_text(node, xpath, use_xpath=false)
  if v_node = (use_xpath && node.at_xpath(xpath)) || (!use_xpath && node.%(xpath))
    value = v_node.text
    return nil if value == XML_NULL_VALUE
    value.to_s.gsub(MOODLE_FILEBASE_TOKEN, IMS_FILEBASE_TOKEN).gsub(SLASH_TOKEN, '/')
  end
end