Class: Presenter::Xml::AssessmentDocument
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Presenter::Xml::AssessmentDocument
- Defined in:
- lib/presenter/xml/parser.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #characters(string) ⇒ Object
- #end_document ⇒ Object
- #end_element_namespace(name, _prefix = nil, _uri = nil) ⇒ Object
-
#initialize(excludes: [], includes: [], bases: [], preferred_keys: {}, list_nodes: [], rootless_list_nodes: {}) ⇒ AssessmentDocument
constructor
A new instance of AssessmentDocument.
- #start_document ⇒ Object
- #start_element(_name, attrs = nil) ⇒ Object
- #start_element_namespace(name, attrs = nil, _prefix = nil, _uri = nil, _namespace = nil) ⇒ Object
Constructor Details
#initialize(excludes: [], includes: [], bases: [], preferred_keys: {}, list_nodes: [], rootless_list_nodes: {}) ⇒ AssessmentDocument
Returns a new instance of AssessmentDocument.
36 37 38 39 40 41 42 43 44 |
# File 'lib/presenter/xml/parser.rb', line 36 def initialize(excludes: [], includes: [], bases: [], preferred_keys: {}, list_nodes: [], rootless_list_nodes: {}) @excludes = excludes @includes = includes @bases = bases @preferred_keys = preferred_keys @list_nodes = list_nodes @rootless_list_nodes = rootless_list_nodes super() { |config| config.huge.strict } end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
99 100 101 |
# File 'lib/presenter/xml/parser.rb', line 99 def output @output end |
Instance Method Details
#characters(string) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/presenter/xml/parser.rb', line 80 def characters(string) if @is_excluding && !@is_including return end stripped = string.strip if stripped.length.zero? return end value = try_as_number stripped if @attrs.length.positive? value = @attrs.to_h.merge({ "value" => value }) end set_value value end |
#end_document ⇒ Object
51 52 53 |
# File 'lib/presenter/xml/parser.rb', line 51 def end_document init! end |
#end_element_namespace(name, _prefix = nil, _uri = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/presenter/xml/parser.rb', line 72 def end_element_namespace(name, _prefix = nil, _uri = nil) @output_position.pop unless is_base?(name) @output_position.pop if at_rootless_list_node_item? @source_position.pop @is_excluding = false if @excludes.include?(name) @is_including = false if @includes.include?(name) end |
#start_document ⇒ Object
46 47 48 49 |
# File 'lib/presenter/xml/parser.rb', line 46 def start_document init! @output = {} end |
#start_element(_name, attrs = nil) ⇒ Object
68 69 70 |
# File 'lib/presenter/xml/parser.rb', line 68 def start_element(_name, attrs = nil) @attrs = attrs end |
#start_element_namespace(name, attrs = nil, _prefix = nil, _uri = nil, _namespace = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/presenter/xml/parser.rb', line 55 def start_element_namespace(name, attrs = nil, _prefix = nil, _uri = nil, _namespace = nil) @source_position << name @output_position << root_key_for_list if at_rootless_list_node_item? @output_position << as_key(name) unless is_base?(name) @is_excluding = true if @excludes.include?(name) @is_including = true if @includes.include?(name) super if encountered_position? || at_list_node_item? set_up_list end write_encounter end |