module Moodle2CC::Moodle2::Parsers::ParserHelper

Constants

FILES_XML
IMS_FILEBASE_TOKEN
MODULE_XML
MOODLE_FILEBASE_TOKEN
SLASH_TOKEN
XML_NULL_VALUE

Public Instance Methods

activity_directories(work_dir, activity_types) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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