Class: CommonCoreParser::Element
- Inherits:
-
Object
- Object
- CommonCoreParser::Element
show all
- Defined in:
- lib/common_core_parser/element.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(xmldoc) ⇒ Element
Returns a new instance of Element.
7
8
9
10
11
|
# File 'lib/common_core_parser/element.rb', line 7
def initialize(xmldoc)
raise(ArgumentError, "Not a LearningStandardItem\n #{xmldoc}") unless xmldoc.name == 'LearningStandardItem'
@data = xmldoc
@children_hash = {}
end
|
Instance Attribute Details
#children_hash ⇒ Object
Returns the value of attribute children_hash.
5
6
7
|
# File 'lib/common_core_parser/element.rb', line 5
def children_hash
@children_hash
end
|
Returns the value of attribute data.
4
5
6
|
# File 'lib/common_core_parser/element.rb', line 4
def data
@data
end
|
Instance Method Details
#add_child(element) ⇒ Object
45
46
47
|
# File 'lib/common_core_parser/element.rb', line 45
def add_child(element)
@children_hash[element.ref_id] = element
end
|
25
26
27
|
# File 'lib/common_core_parser/element.rb', line 25
def children
children_hash.values
end
|
49
50
51
|
# File 'lib/common_core_parser/element.rb', line 49
def code
@code ||= data.xpath('./StatementCodes/StatementCode').first.text.strip
end
|
#error_message ⇒ Object
73
74
75
|
# File 'lib/common_core_parser/element.rb', line 73
def error_message
errors.join(',')
end
|
69
70
71
|
# File 'lib/common_core_parser/element.rb', line 69
def errors
raise RuntimeError
end
|
57
58
59
|
# File 'lib/common_core_parser/element.rb', line 57
def grades
@grades ||= data.xpath('./GradeLevels/GradeLevel').map(&:text).map {|string| convert_grade_string_to_grades(string) }.flatten
end
|
#illigit? ⇒ Boolean
77
78
79
80
81
82
83
84
|
# File 'lib/common_core_parser/element.rb', line 77
def illigit?
return false unless ref_id.blank?
case
when (ref_id.blank? and statement.match(/not applicable/)) then true
when (ref_id.blank? and statement.match(/begins in grade [0-9]+/)) then true
else false
end
end
|
21
22
23
|
# File 'lib/common_core_parser/element.rb', line 21
def parent
@parent ||= Master.instance.elements_hash[parent_ref_id]
end
|
#parent_ref_id ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/common_core_parser/element.rb', line 29
def parent_ref_id
return @parent_ref_id if @parent_ref_id
data.xpath('./RelatedLearningStandardItems/LearningStandardItemRefId').each do |lsiri|
return @parent_ref_id = BrokenDataCorrector.patch_duplicated_parent_ref_ids(self,lsiri.text.strip) if lsiri.attributes['RelationshipType'].value == 'childOf'
end
data.xpath('./PredecessorItems/LearningStandardItemRefId').each do |lsiri|
return @parent_ref_id = BrokenDataCorrector.patch_duplicated_parent_ref_ids(self,lsiri.text.strip)
end
return nil
end
|
#statement ⇒ Object
53
54
55
|
# File 'lib/common_core_parser/element.rb', line 53
def statement
@statement ||= data.xpath('./Statements/Statement').first.text.strip
end
|
13
14
15
|
# File 'lib/common_core_parser/element.rb', line 13
def to_s
"<#{self.class} ref_id: #{ref_id}, parent_ref_id: #{parent_ref_id}, code: #{code}, statement: #{statement}, grades: #{grades.join(',')}>"
end
|
#valid? ⇒ Boolean
65
66
67
|
# File 'lib/common_core_parser/element.rb', line 65
def valid?
errors.blank?
end
|
#valid_grades? ⇒ Boolean
61
62
63
|
# File 'lib/common_core_parser/element.rb', line 61
def valid_grades?
(grades & %w(K HS K-12 01 02 03 04 05 06 07 08 09 10 11 12)) == grades
end
|