class Senkyoshi::Gradebook

Attributes

categories[R]
outcome_definitions[R]

Public Class Methods

get_categories(data) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 49
def self.get_categories(data)
  data.at("CATEGORIES").children.
    each_with_object({}) do |category, categories|
    id = category.attributes["id"].value
    title = category.at("TITLE").
      attributes["value"].value.gsub(".name", "")
    categories[id] = title
  end
end
get_pre_data(data, _) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 35
def self.get_pre_data(data, _)
  categories = get_categories(data)
  data.search("OUTCOMEDEFINITIONS").children.map do |outcome|
    category_id = outcome.at("CATEGORYID").attributes["value"].value
    {
      category: categories[category_id],
      points: outcome.at("POINTSPOSSIBLE").attributes["value"].value,
      content_id: outcome.at("CONTENTID").attributes["value"].value,
      assignment_id: outcome.at("ASIDATAID").attributes["value"].value,
      due_at: outcome.at("DUE").attributes["value"].value,
    }
  end
end
new(resource_id = nil, categories = [], outcome_definitions = []) click to toggle source
Calls superclass method Senkyoshi::FileResource::new
# File lib/senkyoshi/models/gradebook.rb, line 23
def initialize(resource_id = nil, categories = [], outcome_definitions = [])
  super(resource_id)
  @categories = categories
  @outcome_definitions = outcome_definitions
end

Public Instance Methods

canvas_conversion(course, resources = nil) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 81
def canvas_conversion(course, resources = nil)
  convert_categories(course)
  @outcome_definitions.
    select { |outcome_def| OutcomeDefinition.orphan? outcome_def }.
    each { |outcome_def| outcome_def.canvas_conversion course, resources }
  course
end
convert_categories(course) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 66
def convert_categories(course)
  @categories.each do |category|
    if AssignmentGroup.find_group(course, category.last).nil?
      course.assignment_groups <<
        AssignmentGroup.create_assignment_group(category.last)
    end
  end
end
find_outcome_def(outcome_def_id) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 75
def find_outcome_def(outcome_def_id)
  @outcome_definitions.detect do |outcome_def|
    outcome_def.id == outcome_def_id
  end
end
get_outcome_definitions(xml) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 59
def get_outcome_definitions(xml)
  xml.xpath("//OUTCOMEDEFINITION").map do |outcome_def|
    category_id = outcome_def.xpath("CATEGORYID/@value").first.value
    OutcomeDefinition.from(outcome_def, @categories[category_id])
  end
end
iterate_xml(xml_data, _) click to toggle source
# File lib/senkyoshi/models/gradebook.rb, line 29
def iterate_xml(xml_data, _)
  @categories = Gradebook.get_categories(xml_data)
  @outcome_definitions = get_outcome_definitions(xml_data).compact
  self
end