hash_op 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +5 -0
- data/lib/hash_op.rb +2 -1
- data/lib/hash_op/deep.rb +2 -2
- data/lib/hash_op/filter.rb +22 -1
- data/lib/hash_op/math.rb +2 -0
- data/lib/hash_op/read.rb +15 -0
- data/lib/hash_op/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a250a42fdd3666e15b0b12a37579aeff2b8cea32
|
4
|
+
data.tar.gz: 28db054bc0192ccbe687b8872cfba655a6bee7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1cdb95ee97c07ae000d5faea79d46a5b474944418f2123a0761fd419b620aa9f5fafa37e429b86f2296ce6f584f42d8b73c75e54bfdabc3980eccb86664de70
|
7
|
+
data.tar.gz: 9e445c44aefdec481115e3a9f54bd38b5ac0f42e34e904c2f31928ceebb85a4cfb88e7a9e0525e9fc272c30b6a459c429b8bd70f946c4cc918e9f63120131699
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -313,6 +313,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/rchamp
|
|
313
313
|
|
314
314
|
## Revisions
|
315
315
|
|
316
|
+
### 0.3.0
|
317
|
+
|
318
|
+
- Added `Read.values_at_path`
|
319
|
+
- Minor fixes
|
320
|
+
|
316
321
|
### 0.2.0
|
317
322
|
|
318
323
|
- Removed some operations that made no real sense (`Math.sum` and `Math.sum_two`).
|
data/lib/hash_op.rb
CHANGED
data/lib/hash_op/deep.rb
CHANGED
@@ -17,13 +17,13 @@ module HashOp
|
|
17
17
|
# HashOp::Deep.fetch(h, :'b.c.a') # => nil
|
18
18
|
#
|
19
19
|
def fetch(hash, path)
|
20
|
-
fail ArgumentError,
|
20
|
+
fail ArgumentError, "First argument must be an Hash (was #{hash})" unless hash.is_a?(Hash)
|
21
21
|
if path.class.in? [String, Symbol]
|
22
22
|
fetch_with_deep_key(hash, path)
|
23
23
|
elsif path.is_a? Array
|
24
24
|
fetch_with_segments(hash, path)
|
25
25
|
else
|
26
|
-
|
26
|
+
fail ArgumentError, 'Invalid attribute, must be a String or an Array'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
module_function :fetch
|
data/lib/hash_op/filter.rb
CHANGED
@@ -7,7 +7,28 @@ module HashOp
|
|
7
7
|
# Filters an array of hashes according to criteria
|
8
8
|
# on the values of each hash.
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# ```ruby
|
13
|
+
# hashes = [
|
14
|
+
# { value: 123, regexp: "itsamatch", proc: "1+1" },
|
15
|
+
# { value: 123, regexp: "abcdef", proc: "1+2" },
|
16
|
+
# { value: 234, regexp: "abcdef", proc: "1+2" }
|
17
|
+
# ]
|
18
|
+
# HashOp::Filter.filter(hashes, { value: 123 })
|
19
|
+
# => [
|
20
|
+
# [0] {
|
21
|
+
# :proc => "1+1",
|
22
|
+
# :regexp => "itsamatch",
|
23
|
+
# :value => 123
|
24
|
+
# },
|
25
|
+
# [1] {
|
26
|
+
# :proc => "1+2",
|
27
|
+
# :regexp => "abcdef",
|
28
|
+
# :value => 123
|
29
|
+
# }
|
30
|
+
# ]
|
31
|
+
# ```
|
11
32
|
#
|
12
33
|
# @param [Array] hashes array of hashes to be filtered
|
13
34
|
# @param [Hash] criteria the method uses ::match?, see
|
data/lib/hash_op/math.rb
CHANGED
data/lib/hash_op/read.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'hash_op/deep'
|
2
|
+
|
3
|
+
module HashOp
|
4
|
+
|
5
|
+
# A set of method to read values in hashes.
|
6
|
+
module Read
|
7
|
+
|
8
|
+
# @param hashes [Array]
|
9
|
+
# @param path [Array or String]
|
10
|
+
def values_at_path(hashes, path)
|
11
|
+
hashes.map { |hash| Deep.fetch(hash, path) }
|
12
|
+
end
|
13
|
+
module_function :values_at_path
|
14
|
+
end
|
15
|
+
end
|
data/lib/hash_op/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_op
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain Champourlier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/hash_op/mapping.rb
|
122
122
|
- lib/hash_op/math.rb
|
123
123
|
- lib/hash_op/merge.rb
|
124
|
+
- lib/hash_op/read.rb
|
124
125
|
- lib/hash_op/version.rb
|
125
126
|
homepage: https://github.com/rchampourlier/hash_op
|
126
127
|
licenses: []
|