summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-04-08 13:12:06 -0600
committermo khan <mo@mokhan.ca>2015-04-08 13:12:06 -0600
commit81f1e9d793c896953f645e46331854e4c7127ea0 (patch)
tree1a268031c72eb868ca6febbf0a8c08fe429592b9
parent55a6d4ba7f1f6f349bebaed82cf6b5158e8a7eb5 (diff)
dynamically pass parameters to xml node based on whether there is text content or not.
-rw-r--r--lib/scale/node.rb21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/scale/node.rb b/lib/scale/node.rb
index 00b3b7c..c71d589 100644
--- a/lib/scale/node.rb
+++ b/lib/scale/node.rb
@@ -28,17 +28,9 @@ module Scale
end
def append_to(builder)
- if content.nil?
- builder.send(xml_tag.to_sym, xml_attributes) do
- each do |node|
- node.append_to(builder)
- end
- end
- else
- builder.send(xml_tag.to_sym, content, xml_attributes) do
- each do |node|
- node.append_to(builder)
- end
+ builder.send(xml_tag.to_sym, *xml_parameters) do
+ each do |node|
+ node.append_to(builder)
end
end
end
@@ -46,5 +38,12 @@ module Scale
def xml_attributes
attributes.delete_if { |key, value| value.nil? }
end
+
+ private
+
+ def xml_parameters
+ return [xml_attributes] if content.nil?
+ [content, xml_attributes]
+ end
end
end