gorillib 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/gorillib.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gorillib}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Infochimps"]
12
- s.date = %q{2011-04-24}
12
+ s.date = %q{2011-05-05}
13
13
  s.description = %q{Gorillib: infochimps lightweight subset of ruby convenience methods}
14
14
  s.email = %q{coders@infochimps.org}
15
15
  s.extra_rdoc_files = [
@@ -27,12 +27,14 @@ Gem::Specification.new do |s|
27
27
  "gorillib.gemspec",
28
28
  "lib/gorillib.rb",
29
29
  "lib/gorillib/array/compact_blank.rb",
30
+ "lib/gorillib/array/deep_compact.rb",
30
31
  "lib/gorillib/array/extract_options.rb",
31
32
  "lib/gorillib/base.rb",
32
33
  "lib/gorillib/datetime/flat.rb",
33
34
  "lib/gorillib/datetime/parse.rb",
34
35
  "lib/gorillib/enumerable/sum.rb",
35
36
  "lib/gorillib/hash/compact.rb",
37
+ "lib/gorillib/hash/deep_compact.rb",
36
38
  "lib/gorillib/hash/deep_merge.rb",
37
39
  "lib/gorillib/hash/keys.rb",
38
40
  "lib/gorillib/hash/reverse_merge.rb",
@@ -54,6 +56,7 @@ Gem::Specification.new do |s|
54
56
  "lib/gorillib/string/inflections.rb",
55
57
  "lib/gorillib/string/truncate.rb",
56
58
  "spec/blank_spec.rb",
59
+ "spec/deep_compact_spec.rb",
57
60
  "spec/gorillib_spec.rb",
58
61
  "spec/numeric_spec.rb",
59
62
  "spec/rcov.opts",
@@ -89,10 +92,11 @@ Gem::Specification.new do |s|
89
92
  s.homepage = %q{http://infochimps.com/labs}
90
93
  s.licenses = ["MIT"]
91
94
  s.require_paths = ["lib"]
92
- s.rubygems_version = %q{1.5.0}
95
+ s.rubygems_version = %q{1.3.7}
93
96
  s.summary = %q{include only what you need. No dependencies, no creep}
94
97
  s.test_files = [
95
98
  "spec/blank_spec.rb",
99
+ "spec/deep_compact_spec.rb",
96
100
  "spec/gorillib_spec.rb",
97
101
  "spec/numeric_spec.rb",
98
102
  "spec/spec_helper.rb",
@@ -124,6 +128,7 @@ Gem::Specification.new do |s|
124
128
  ]
125
129
 
126
130
  if s.respond_to? :specification_version then
131
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
127
132
  s.specification_version = 3
128
133
 
129
134
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -0,0 +1,22 @@
1
+ require 'gorillib/object/blank'
2
+
3
+ #
4
+ # deep_compact! removes all 'blank?' elements in the array in place, recursively
5
+ #
6
+ class Array
7
+ def deep_compact!
8
+ self.map! do |val|
9
+ case val
10
+ when Hash
11
+ val = val.deep_compact!
12
+ when Array
13
+ val = val.deep_compact!
14
+ when String
15
+ val = nil if val.blank?
16
+ end
17
+ val
18
+ end
19
+ self.compact!
20
+ self.blank? ? nil : self
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require 'gorillib/object/blank'
2
+
3
+ #
4
+ # deep_compact! removes all keys with 'blank?' values in the hash, in place, recursively
5
+ #
6
+ class Hash
7
+ def deep_compact!
8
+ self.each do |key, val|
9
+ case val
10
+ when Hash
11
+ val = val.deep_compact!
12
+ self.delete(key) if val.blank?
13
+ when Array
14
+ val = val.deep_compact!
15
+ self.delete(key) if val.blank?
16
+ when String
17
+ self.delete(key) if val.blank?
18
+ when nil
19
+ self.delete(key)
20
+ end
21
+ end
22
+ self.blank? ? nil : self
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'gorillib/hash/deep_compact'
3
+ require 'gorillib/array/deep_compact'
4
+
5
+ describe Hash do
6
+
7
+ it "should respond to the method deep_compact!" do
8
+ { }.should respond_to :deep_compact!
9
+ end
10
+
11
+ it "should return nil if all values evaluate as blank" do
12
+ { :a=>nil, :b=>"", :c=>[] }.deep_compact!.should be nil
13
+ end
14
+
15
+ it "should return a hash with all blank values removed recursively" do
16
+ @test_hash = {:e=>["",nil,[],{},"foo",{:a=>[nil,{:c=>["","",[]]}],:b=>nil }]}
17
+ @test_hash.deep_compact!.should == {:e=>["foo"]}
18
+ end
19
+
20
+ end
21
+
22
+ describe Array do
23
+
24
+ it "should respond to the method deep_compact!" do
25
+ [ ].should respond_to :deep_compact!
26
+ end
27
+
28
+ it "should return nil if all values evaluate as blank" do
29
+ [nil, '', { }].deep_compact!.should be nil
30
+ end
31
+
32
+ it "should return a hash with all blank values removed recursively" do
33
+ @test_hash = ["",nil,[],{},"foo",{:a=>[nil,{:c=>["","",[]]}],:b=>nil }]
34
+ @test_hash.deep_compact!.should == ["foo"]
35
+ end
36
+ end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorillib
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.5
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
6
11
  platform: ruby
7
12
  authors:
8
13
  - Infochimps
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-04-24 00:00:00 -05:00
18
+ date: 2011-05-05 00:00:00 -05:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,11 @@ dependencies:
21
26
  requirements:
22
27
  - - ~>
23
28
  - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 0
24
34
  version: 0.6.0
25
35
  type: :development
26
36
  version_requirements: *id001
@@ -32,6 +42,11 @@ dependencies:
32
42
  requirements:
33
43
  - - ~>
34
44
  - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 1
48
+ - 5
49
+ - 2
35
50
  version: 1.5.2
36
51
  type: :development
37
52
  version_requirements: *id002
@@ -43,6 +58,9 @@ dependencies:
43
58
  requirements:
44
59
  - - ">="
45
60
  - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
46
64
  version: "0"
47
65
  type: :development
48
66
  version_requirements: *id003
@@ -66,12 +84,14 @@ files:
66
84
  - gorillib.gemspec
67
85
  - lib/gorillib.rb
68
86
  - lib/gorillib/array/compact_blank.rb
87
+ - lib/gorillib/array/deep_compact.rb
69
88
  - lib/gorillib/array/extract_options.rb
70
89
  - lib/gorillib/base.rb
71
90
  - lib/gorillib/datetime/flat.rb
72
91
  - lib/gorillib/datetime/parse.rb
73
92
  - lib/gorillib/enumerable/sum.rb
74
93
  - lib/gorillib/hash/compact.rb
94
+ - lib/gorillib/hash/deep_compact.rb
75
95
  - lib/gorillib/hash/deep_merge.rb
76
96
  - lib/gorillib/hash/keys.rb
77
97
  - lib/gorillib/hash/reverse_merge.rb
@@ -93,6 +113,7 @@ files:
93
113
  - lib/gorillib/string/inflections.rb
94
114
  - lib/gorillib/string/truncate.rb
95
115
  - spec/blank_spec.rb
116
+ - spec/deep_compact_spec.rb
96
117
  - spec/gorillib_spec.rb
97
118
  - spec/numeric_spec.rb
98
119
  - spec/rcov.opts
@@ -138,22 +159,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
159
  requirements:
139
160
  - - ">="
140
161
  - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
141
165
  version: "0"
142
166
  required_rubygems_version: !ruby/object:Gem::Requirement
143
167
  none: false
144
168
  requirements:
145
169
  - - ">="
146
170
  - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
147
174
  version: "0"
148
175
  requirements: []
149
176
 
150
177
  rubyforge_project:
151
- rubygems_version: 1.5.0
178
+ rubygems_version: 1.3.7
152
179
  signing_key:
153
180
  specification_version: 3
154
181
  summary: include only what you need. No dependencies, no creep
155
182
  test_files:
156
183
  - spec/blank_spec.rb
184
+ - spec/deep_compact_spec.rb
157
185
  - spec/gorillib_spec.rb
158
186
  - spec/numeric_spec.rb
159
187
  - spec/spec_helper.rb