document_hash 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/document_hash/core.rb +13 -0
- data/lib/document_hash/version.rb +1 -1
- data/spec/lib/document_spec.rb +11 -0
- metadata +1 -1
data/lib/document_hash/core.rb
CHANGED
@@ -55,6 +55,18 @@ module DocumentHash
|
|
55
55
|
self
|
56
56
|
end
|
57
57
|
|
58
|
+
def to_hash
|
59
|
+
Hash[
|
60
|
+
self.collect do |k,v|
|
61
|
+
if v.is_a? DocumentHash::Core
|
62
|
+
[ k, v.to_hash ]
|
63
|
+
else
|
64
|
+
[ k, v ]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
58
70
|
private
|
59
71
|
|
60
72
|
attr_accessor :parent, :parent_key
|
@@ -84,5 +96,6 @@ module DocumentHash
|
|
84
96
|
hash[(key.to_sym rescue key) || key] = hash.delete(key)
|
85
97
|
end
|
86
98
|
end
|
99
|
+
|
87
100
|
end
|
88
101
|
end
|
data/spec/lib/document_spec.rb
CHANGED
@@ -135,4 +135,15 @@ describe DocumentHash::Core do
|
|
135
135
|
subject[:inner][:attribute].should == "hola"
|
136
136
|
end
|
137
137
|
|
138
|
+
it "converts itself to a hash", focus:true do
|
139
|
+
subject = DocumentHash::Core[{ test: "test" }]
|
140
|
+
hash = subject.to_hash
|
141
|
+
hash.should be_an_instance_of Hash
|
142
|
+
end
|
143
|
+
|
144
|
+
it "converts internal hashes to hash", focus: true do
|
145
|
+
subject = DocumentHash::Core[{ test: { inner: "value" } }]
|
146
|
+
hash = subject.to_hash
|
147
|
+
hash[:test].should be_an_instance_of Hash
|
148
|
+
end
|
138
149
|
end
|