Class: Senkyoshi::Rule

Inherits:
FileResource show all
Defined in:
lib/senkyoshi/models/rule.rb

Constant Summary collapse

CRITERIA_MAP =
{
  grade_completed_criteria: GradeCompletedCriteria,
  content_reviewed_criteria: ContentReviewedCriteria,
  grade_range_criteria: GradeRangeCriteria,
  grade_range_percent_criteria: GradeRangePercentCriteria,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileResource

#create_module, from

Methods inherited from Resource

#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, get_pre_data, #matches_xid?, #strip_xid

Constructor Details

#initialize(resource_id) ⇒ Rule

Returns a new instance of Rule.



33
34
35
36
# File 'lib/senkyoshi/models/rule.rb', line 33

def initialize(resource_id)
  super(resource_id)
  @criteria_list = []
end

Instance Attribute Details

#content_idObject (readonly)

Returns the value of attribute content_id.



24
25
26
# File 'lib/senkyoshi/models/rule.rb', line 24

def content_id
  @content_id
end

#criteria_listObject (readonly)

Returns the value of attribute criteria_list.



24
25
26
# File 'lib/senkyoshi/models/rule.rb', line 24

def criteria_list
  @criteria_list
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/senkyoshi/models/rule.rb', line 24

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



24
25
26
# File 'lib/senkyoshi/models/rule.rb', line 24

def title
  @title
end

Instance Method Details

#canvas_conversion(course, _resources) ⇒ Object



54
55
56
57
58
59
# File 'lib/senkyoshi/models/rule.rb', line 54

def canvas_conversion(course, _resources)
  @criteria_list.each do |criteria|
    criteria.canvas_conversion(course, @content_id, _resources)
  end
  course
end

#get_criteria_list(xml) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/senkyoshi/models/rule.rb', line 38

def get_criteria_list(xml)
  xml.children.select { |child_xml| !child_xml.blank? }.
    map do |child_xml|
      criteria = CRITERIA_MAP[child_xml.name.downcase.to_sym]
      criteria.from_xml(child_xml) if !criteria.nil?
    end.compact
end

#iterate_xml(xml, _pre_data = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/senkyoshi/models/rule.rb', line 46

def iterate_xml(xml, _pre_data = nil)
  @title = xml.xpath("./TITLE/@value").text
  @content_id = xml.xpath("./CONTENT_ID/@value").text
  @id = xml.xpath("./@id").text
  @criteria_list = get_criteria_list(xml.xpath("./CRITERIA_LIST"))
  self
end