Module: Ksef::FA3::ElementTree
- Defined in:
- lib/ksef/fa3/element_tree.rb
Overview
Reads an XML element's subtree into the nested-Hash shape Serializer consumes.
A leaf becomes its text, a parent becomes a Hash, and a name that repeats becomes an Array — which is exactly the shape Serializer writes back, so a subtree read this way round-trips without the model having to understand any of it.
Parser uses it for Adnotacje, a group of eight annotations with real tax
consequences and far too much structure to model field by field in 0.1. Reading it
structurally is what stops re-serialisation from silently resetting a declaration the
document made (see Invoice::DEFAULT_ANNOTATIONS).
It carries no FA(3) knowledge, which is why it lives apart from the parser.
Class Method Summary collapse
-
.to_hash(node) ⇒ Hash?
Nil when the node is absent, so a caller's default can apply.
Class Method Details
.to_hash(node) ⇒ Hash?
Returns nil when the node is absent, so a caller's default can apply.
21 22 23 24 25 26 27 |
# File 'lib/ksef/fa3/element_tree.rb', line 21 def to_hash(node) return nil if node.nil? node.element_children.each_with_object({}) do |child, acc| store(acc, child.name, value_of(child)) end end |