Commit 1c71206
Changed files (2)
lib
scale
spec
lib/scale/node.rb
@@ -2,6 +2,7 @@ require 'virtus'
module Scale
module Node
+ include Enumerable
include Virtus.module
def children
@@ -12,6 +13,12 @@ module Scale
children.push(node)
end
+ def each
+ children.each do |child|
+ yield child
+ end
+ end
+
def to_xml
builder = Nokogiri::XML::Builder.new do |xml|
append_to(xml)
@@ -21,7 +28,7 @@ module Scale
def append_to(xml)
xml.send(xml_tag.to_sym, xml_attributes) do
- children.each do |node|
+ each do |node|
node.append_to(xml)
end
end
spec/node_spec.rb
@@ -12,4 +12,12 @@ describe Scale::Node do
expect(subject.xml_attributes).to be_empty
end
end
+
+ describe "#add" do
+ it 'adds a child node' do
+ child = Object.new
+ subject.add(child)
+ expect(subject).to include(child)
+ end
+ end
end