Class: XmlTreeBuilder
- Inherits:
-
XmlNodeBuilder
- Object
- XmlNodeBuilder
- XmlTreeBuilder
- Defined in:
- app/services/xml_tree_builder.rb
Constant Summary
Constants inherited from XmlNodeBuilder
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#root_builder_options ⇒ Object
readonly
Returns the value of attribute root_builder_options.
Attributes inherited from XmlNodeBuilder
Instance Method Summary collapse
- #build ⇒ Nokogiri::XML::Element
-
#initialize(children: [], **options) ⇒ XmlTreeBuilder
constructor
A new instance of XmlTreeBuilder.
- #null_builder ⇒ Object
-
#parse_child_entries(entries) ⇒ Array<Nokogiri::XML::Node>
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #root_builder ⇒ Object
Methods inherited from XmlNodeBuilder
#build_document, #xml_document_args, #xml_version
Constructor Details
#initialize(children: [], **options) ⇒ XmlTreeBuilder
Returns a new instance of XmlTreeBuilder.
70 71 72 73 74 75 |
# File 'app/services/xml_tree_builder.rb', line 70 def initialize(children: [], **) @root_builder_options = .dup @children = parse_child_entries(children) super(document: document) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'app/services/xml_tree_builder.rb', line 4 def children @children end |
#root_builder_options ⇒ Object (readonly)
Returns the value of attribute root_builder_options.
4 5 6 |
# File 'app/services/xml_tree_builder.rb', line 4 def @root_builder_options end |
Instance Method Details
#build ⇒ Nokogiri::XML::Element
21 22 23 24 25 26 27 28 |
# File 'app/services/xml_tree_builder.rb', line 21 def build nodes = children.map(&:build) nodes.each do |child| root_builder.add_child(child) end node end |
#null_builder ⇒ Object
6 7 8 |
# File 'app/services/xml_tree_builder.rb', line 6 def null_builder @null_builder ||= XmlNullBuilder.new(**) end |
#parse_child_entries(entries) ⇒ Array<Nokogiri::XML::Node>
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/xml_tree_builder.rb', line 35 def parse_child_entries(entries) instances = [:default] builders = entries.map do |child_entry| child_entry.values.map do |child_args| multiple_children = child_args[:multiple] || false if multiple_children = child_args[:object_method] method_args = child_args[:args] || [] instances = root_builder.presenter.send(, *method_args) end instances.each_with_index.map do |_instance, i| builder_args = child_args.dup builder_args[:presenter] = root_builder.presenter builder_args[:document] = document if multiple_children builder_args[:index] = i builder_args.delete(:multiple) end builder_args.delete(:object_method) builder_args.delete(:args) self.class.new(**builder_args) end end end builders.flatten end |
#root_builder ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/services/xml_tree_builder.rb', line 10 def root_builder @root_builder ||= begin default_builder = XmlElementBuilder.new(**) null_builder if default_builder.blank? default_builder end end |