numeric_hash 0.2.0 → 0.3.0
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/numeric_hash/version.rb +1 -1
- data/lib/numeric_hash.rb +16 -4
- data/numeric_hash.gemspec +1 -1
- metadata +7 -5
data/lib/numeric_hash/version.rb
CHANGED
data/lib/numeric_hash.rb
CHANGED
@@ -172,13 +172,25 @@ class NumericHash < Hash
|
|
172
172
|
[:to_f, :to_i, :to_int].each do |convert_method|
|
173
173
|
define_method("map_#{convert_method}".to_sym) { map_values(&convert_method) }
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
|
+
# Maps each numeric value using the specified block.
|
177
|
+
#
|
178
|
+
# @hash # => { :a => 1, :b => { :c => 2, :d => 3 } }
|
179
|
+
# @hash.map_numeric { |value| "X" * value } # => { :a => "X", :b => { :c => "XX", :d => "XXX" } }
|
180
|
+
# @hash.collect_numeric(&:to_s) # => { :a => "1", :b => { :c => "2", :d => "3" } }
|
181
|
+
#
|
182
|
+
def collect_numeric(&block)
|
183
|
+
map_to_hash do |key, value|
|
184
|
+
[key, value.is_a?(NumericHash) ? value.collect_numeric(&block) : yield(value)]
|
185
|
+
end
|
186
|
+
end
|
187
|
+
alias_method :map_numeric, :collect_numeric
|
188
|
+
|
176
189
|
# Converts the NumericHash into a regular Hash.
|
177
190
|
#
|
178
191
|
def to_hash
|
179
|
-
|
180
|
-
|
181
|
-
hash
|
192
|
+
map_to_hash do |key, value|
|
193
|
+
[key, value.is_a?(NumericHash) ? value.to_hash : value]
|
182
194
|
end
|
183
195
|
end
|
184
196
|
|
data/numeric_hash.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Defines a hash whose values are Numeric or additional nested NumericHashes.}
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
|
-
s.add_dependency('enumerate_hash_values')
|
15
|
+
s.add_dependency('enumerate_hash_values', '>= 0.2.0')
|
16
16
|
|
17
17
|
s.rubyforge_project = "numeric_hash"
|
18
18
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numeric_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Clyde Law
|
@@ -26,10 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 23
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 0.2.0
|
33
35
|
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
description: Defines a hash whose values are Numeric or additional nested NumericHashes.
|