pump 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pump/version.rb +1 -1
- data/lib/pump/xml/node.rb +5 -1
- data/lib/pump/xml/tag.rb +3 -1
- data/lib/pump/xml.rb +9 -1
- data/spec/pump/xml_spec.rb +8 -0
- metadata +1 -1
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml/node.rb
CHANGED
@@ -2,7 +2,6 @@ module Pump
|
|
2
2
|
class Xml
|
3
3
|
class Node
|
4
4
|
attr_reader :name, :attributes, :nodes, :options
|
5
|
-
attr_writer :level
|
6
5
|
|
7
6
|
def initialize(name, attributes={}, nodes=[], options={})
|
8
7
|
@name = name
|
@@ -15,6 +14,11 @@ module Pump
|
|
15
14
|
def to_s
|
16
15
|
end
|
17
16
|
|
17
|
+
def level=(new_level)
|
18
|
+
@level = new_level
|
19
|
+
nodes.each{|node| node.level = @level + 1}
|
20
|
+
end
|
21
|
+
|
18
22
|
private
|
19
23
|
|
20
24
|
def add_node(node)
|
data/lib/pump/xml/tag.rb
CHANGED
data/lib/pump/xml.rb
CHANGED
@@ -38,7 +38,15 @@ module Pump
|
|
38
38
|
|
39
39
|
def sub_tags
|
40
40
|
tag_config.map do |config|
|
41
|
-
|
41
|
+
build_tag(config)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_tag(config)
|
46
|
+
tag_name, method_name = config.keys.first, config.values.first
|
47
|
+
if method_name.is_a?(Array)
|
48
|
+
Tag.new(tag_name, config[:attributes], method_name.map{|conf| build_tag(conf) }, config)
|
49
|
+
else
|
42
50
|
Tag.new(tag_name, config[:attributes], Value.new(method_name), config)
|
43
51
|
end
|
44
52
|
end
|
data/spec/pump/xml_spec.rb
CHANGED
@@ -199,5 +199,13 @@ describe Pump::Xml do
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
202
|
+
|
203
|
+
context "deeper nesting" do
|
204
|
+
let(:xml) { Pump::Xml.new('person', [{:name => :name}, {:parent => [{:name => :name}, {:age => :age}]}], :instruct => false) }
|
205
|
+
|
206
|
+
it "returns xml string" do
|
207
|
+
xml.encode(person).should eql("<person>\n <name>Benny</name>\n <parent>\n <name>Benny</name>\n <age>9</age>\n </parent>\n</person>")
|
208
|
+
end
|
209
|
+
end
|
202
210
|
end
|
203
211
|
end
|