Class: CommonCoreParser::Master
- Includes:
- Singleton
- Defined in:
- lib/common_core_parser/master.rb
Constant Summary collapse
- ELEMENT_NAMES =
[:elements, :domains, :clusters, :standards, :components, :subject_grades, :standard_types]
Instance Method Summary collapse
- #add_element(element) ⇒ Object
- #delete_element(element) ⇒ Object
-
#initialize ⇒ Master
constructor
A new instance of Master.
- #load_ela ⇒ Object
- #load_elements_from_paths(*paths) ⇒ Object
- #load_math ⇒ Object
Constructor Details
#initialize ⇒ Master
Returns a new instance of Master.
8 9 10 11 12 |
# File 'lib/common_core_parser/master.rb', line 8 def initialize ELEMENT_NAMES.each do |element_name| instance_variable_set("@#{element_name}_hash",HashWithIndifferentAccess.new) end end |
Instance Method Details
#add_element(element) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/common_core_parser/master.rb', line 38 def add_element(element) return if element.illigit? raise "#{element} has same ref_id as #{@elements_hash[element.ref_id]}" if @elements_hash[element.ref_id] @elements_hash[element.ref_id] = element instance_variable_get(instance_variable_name_for_element(element))[element.ref_id] = element end |
#delete_element(element) ⇒ Object
45 46 47 48 |
# File 'lib/common_core_parser/master.rb', line 45 def delete_element(element) @elements_hash.delete(element.classified_ref_id) instance_variable_get(instance_variable_name_for_element(element)).delete(element.ref_id) end |
#load_ela ⇒ Object
18 19 20 |
# File 'lib/common_core_parser/master.rb', line 18 def load_ela load_elements_from_paths(DATA_PATH+'/ELA-Literacy.xml',DATA_PATH+'/ELA/**/*.xml') end |
#load_elements_from_paths(*paths) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/common_core_parser/master.rb', line 22 def load_elements_from_paths(*paths) self.send(:initialize) paths.flatten.each do |path| Dir.glob(path).map do |filename| xml = Nokogiri::XML(File.open(filename)) xml.xpath('//LearningStandardItem').each do |learning_standard_item| klass = get_class_from_element(learning_standard_item) add_element(klass.new(learning_standard_item)) end end end correct_bad_data reunite_children_with_parents return standards end |