module Moodle2CC::Moodle2Converter::ConverterHelper

Constants

ACTIVITY_LOOKUP
ASSESSMENT_SUFFIX
ASSIGNMENT_SUFFIX
CHAPTER_SUFFIX
CHOICE_ASSESSMENT_SUFFIX
COURSE_SUFFIX
DISCUSSION_SUFFIX
EXTERNAL_URL_SUFFIX
FEEDBACK_ASSESSMENT_SUFFIX
FILE_SUFFIX
FOLDER_SUFFIX
GLOSSARY_SUFFIX
INTRO_SUFFIX
LTI_SUFFIX
MAX_TITLE_LENGTH
MODULE_SUFFIX
PAGE_SUFFIX
QUESTIONNAIRE_ASSESSMENT_SUFFIX
QUESTION_BANK_SUFFIX
SUMMARY_PAGE_SUFFIX

Public Instance Methods

activity_content_type(activity) click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 91
def activity_content_type(activity)
  if lookup = ACTIVITY_LOOKUP[activity.class]
    lookup[:content_type]
  else
    raise "Unknown activity type: #{activity.class}"
  end
end
generate_unique_identifier() click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 50
def generate_unique_identifier
  "m2#{SecureRandom.uuid.gsub('-', '')}"
end
generate_unique_identifier_for(id, suffix = nil) click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 74
def generate_unique_identifier_for(id, suffix = nil)
  unique_id = "m2#{Digest::MD5.hexdigest(id.to_s)}#{suffix}"
  id_set = Moodle2Converter::Migrator.unique_id_set
  if id_set.include?(unique_id)
    # i was under the impression that moodle ids would be unique themselves
    # but i have been apparently misinformed
    original_id = unique_id
    index = 0
    while id_set.include?(unique_id)
      index += 1
      unique_id = "#{original_id}#{index}"
    end
  end
  id_set << unique_id
  unique_id
end
generate_unique_identifier_for_activity(activity) click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 64
def generate_unique_identifier_for_activity(activity)
  if lookup = ACTIVITY_LOOKUP[activity.class]
    unique_id = generate_unique_identifier_for(activity.id, lookup[:suffix])
    Moodle2Converter::Migrator.activity_id_map[activity.hash] = unique_id
    unique_id
  else
    raise "Unknown activity type: #{activity.class}"
  end
end
generate_unique_resource_path(base_path, readable_name, file_extension = 'html') click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 44
def generate_unique_resource_path(base_path, readable_name, file_extension = 'html')
  file_name_suffix = readable_name ? Moodle2CC::CanvasCC::Models::Page.convert_name_to_url(readable_name) : ''
  ext = file_extension ? ".#{file_extension}" : ''
  File.join(base_path, generate_unique_identifier(), "#{file_name_suffix}#{ext}")
end
get_unique_identifier_for_activity(activity) click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 54
def get_unique_identifier_for_activity(activity)
  # use when we want to retrieve an existing id, not generate a new one
  id = Moodle2Converter::Migrator.activity_id_map[activity.hash]
  unless id
    Moodle2CC::OutputLogger.logger.info "could not find matching id for #{activity.inspect}"
    id = generate_unique_identifier_for_activity(activity)
  end
  id
end
truncate_text(text, max_length = nil, ellipsis = '...') click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 103
def truncate_text(text, max_length = nil, ellipsis = '...')
  max_length ||= MAX_TITLE_LENGTH
  return text if !text || text.length <= max_length

  actual_length = max_length - ellipsis.length

  # First truncate the text down to the bytes max, then lop off any invalid
  # unicode characters at the end.
  truncated = text[0,actual_length][/.{0,#{actual_length}}/mu]
  truncated + ellipsis
end
workflow_state(moodle_visibility) click to toggle source
# File lib/moodle2cc/moodle2converter/converter_helper.rb, line 99
def workflow_state(moodle_visibility)
  moodle_visibility ? CanvasCC::Models::WorkflowState::ACTIVE : CanvasCC::Models::WorkflowState::UNPUBLISHED
end