Class: Services::MdsSaxHandler
- Inherits:
-
Object
- Object
- Services::MdsSaxHandler
- Includes:
- LibXML::XML::SaxParser::Callbacks
- Defined in:
- app/utils/services/mds_xml_file_parser.rb
Overview
—————————————————————————-# Using LibXML with SAX API for performance reasons. # —————————————————————————-#
Constant Summary collapse
- ROOT_NESTING_LEVEL =
0
- ATTRIBUTE_NESTING_LEVEL =
1
- TEXT_NESTING_LEVEL =
2
Instance Attribute Summary collapse
-
#assessment_hash ⇒ Object
readonly
Returns the value of attribute assessment_hash.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize ⇒ MdsSaxHandler
constructor
A new instance of MdsSaxHandler.
- #on_characters(text) ⇒ Object
- #on_end_element(element_name) ⇒ Object
- #on_error(error) ⇒ Object
- #on_start_element(element_name, attributes) ⇒ Object
Constructor Details
#initialize ⇒ MdsSaxHandler
Returns a new instance of MdsSaxHandler.
74 75 76 77 78 79 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 74 def initialize @assessment_hash = {} @file_errors = [] @xml_nesting_level = ROOT_NESTING_LEVEL @element_text = nil end |
Instance Attribute Details
#assessment_hash ⇒ Object (readonly)
Returns the value of attribute assessment_hash.
68 69 70 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 68 def assessment_hash @assessment_hash end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
68 69 70 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 68 def errors @errors end |
Instance Method Details
#on_characters(text) ⇒ Object
89 90 91 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 89 def on_characters(text) @element_text << text if @xml_nesting_level == TEXT_NESTING_LEVEL end |
#on_end_element(element_name) ⇒ Object
93 94 95 96 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 93 def on_end_element(element_name) @assessment_hash[element_name.downcase] = @element_text.strip if !@element_text.nil? && @xml_nesting_level == TEXT_NESTING_LEVEL @xml_nesting_level -= 1 end |
#on_error(error) ⇒ Object
98 99 100 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 98 def on_error(error) @file_errors << error. end |
#on_start_element(element_name, attributes) ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/utils/services/mds_xml_file_parser.rb', line 81 def on_start_element(element_name, attributes) if @xml_nesting_level == ROOT_NESTING_LEVEL @file_errors << "XML root element ASSESSMENT not found." unless element_name == "ASSESSMENT" end @xml_nesting_level += 1 @element_text = '' end |