module Dotremap::XmlTree
Attributes
parent[RW]
Public Instance Methods
add_child(*objects)
click to toggle source
# File lib/dotremap/xml_tree.rb, line 4 def add_child(*objects) objects.each do |object| childs << object end childs.each do |child| child.parent = self end end
search_childs(klass)
click to toggle source
# File lib/dotremap/xml_tree.rb, line 14 def search_childs(klass) childs.select { |c| c.is_a?(klass) } end
to_xml(distance_between_childs = 0)
click to toggle source
# File lib/dotremap/xml_tree.rb, line 18 def to_xml(distance_between_childs = 0) tag_name = self.class.to_s.split("::").last.downcase newline_count = distance_between_childs + 1 [ "<#{tag_name}>", childs.map(&:to_xml).join("\n" * newline_count).gsub(/^/, " "), "</#{tag_name}>", ].join("\n") end
Private Instance Methods
childs()
click to toggle source
# File lib/dotremap/xml_tree.rb, line 35 def childs @childs ||= [] end