Module: Goldendocx::HasChildren

Extended by:
ActiveSupport::Concern
Included in:
Element
Defined in:
lib/goldendocx/has_children.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#childrenObject



94
95
96
# File 'lib/goldendocx/has_children.rb', line 94

def children
  self.class.children.keys.flat_map { |name| send(name) }.compact
end

#read_child(child_node) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/goldendocx/has_children.rb', line 104

def read_child(child_node)
  name, options = self.class.children.find do |_, opts|
    opts[:class_name].constantize.adapt?(child_node)
  end
  if name.present?
    child = options[:class_name].constantize.read_from(child_node)
    send("append_#{name.to_s.singularize}", child)
  else
    unparsed_children << child_node
  end
end

#read_children(xml_node) ⇒ Object



98
99
100
101
102
# File 'lib/goldendocx/has_children.rb', line 98

def read_children(xml_node)
  xml_node.children.each do |child_node|
    read_child(child_node)
  end
end