document_hash 0.0.14 → 0.0.15

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.
@@ -103,13 +103,21 @@ module DocumentHash
103
103
  self
104
104
  end
105
105
 
106
- def to_hash
106
+ def to_hash options = {}
107
107
  Hash[
108
108
  self.collect do |k,v|
109
+ if options[:stringify_keys]
110
+ key = k.to_s
111
+ elsif options[:symbolize_keys]
112
+ key = k.to_sym
113
+ else
114
+ key = k
115
+ end
116
+
109
117
  if v.is_a? DocumentHash::Core
110
- [ k, v.to_hash ]
118
+ [ key, v.to_hash ]
111
119
  else
112
- [ k, v ]
120
+ [ key, v ]
113
121
  end
114
122
  end
115
123
  ]
@@ -1,3 +1,3 @@
1
1
  module DocumentHash
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -159,18 +159,32 @@ describe DocumentHash::Core do
159
159
  subject.touch!
160
160
  end
161
161
 
162
- it "converts itself to a hash" do
162
+ it "returns a hash" do
163
163
  subject = DocumentHash::Core[{ test: "test" }]
164
164
  hash = subject.to_hash
165
165
  hash.should be_an_instance_of Hash
166
166
  end
167
167
 
168
- it "converts internal hashes to hash" do
168
+ it "internal hashes are hashes" do
169
169
  subject = DocumentHash::Core[{ test: { inner: "value" } }]
170
170
  hash = subject.to_hash
171
171
  hash[:test].should be_an_instance_of Hash
172
172
  end
173
173
 
174
+ it "return keys stringified as an option" do
175
+ subject = DocumentHash::Core[{ test: "test" }]
176
+ hash = subject.to_hash stringify_keys: true
177
+
178
+ hash.keys.all?{ |k| k === String }
179
+ end
180
+
181
+ it "return keys symbolized keys as an option" do
182
+ subject = DocumentHash::Core[{ test: "test" }]
183
+ hash = subject.to_hash symbolize_keys: true
184
+
185
+ hash.keys.all?{ |k| k === Symbol }
186
+ end
187
+
174
188
  it "can access values thru methods" do
175
189
  subject = DocumentHash::Core[{ test: "value" }]
176
190
  subject.test.should == "value"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: document_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-13 00:00:00.000000000 Z
12
+ date: 2015-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec