hash_op 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ee4ebeea9d4222628d2e8bc1a35ac27ff6b219
4
- data.tar.gz: 9cc047ece2b3c87a1baf144f17f3a3434da43afc
3
+ metadata.gz: a250a42fdd3666e15b0b12a37579aeff2b8cea32
4
+ data.tar.gz: 28db054bc0192ccbe687b8872cfba655a6bee7b4
5
5
  SHA512:
6
- metadata.gz: bb145f094b7bd06a0f77ad34b81e0b674d6bb74daa5358a1b60655dc171be67e1113ce39980aee0a99dd26aafaf289e8a04c293930ebebaf722a874868c8fd7f
7
- data.tar.gz: 302dede0a9005b1284bb3d405e35937defebc45ad6744f635b7bcb8b15a351460ec43487031a46e6439ff795296fb8da87c3c4571691b0f690e78ce32ab93fec
6
+ metadata.gz: f1cdb95ee97c07ae000d5faea79d46a5b474944418f2123a0761fd419b620aa9f5fafa37e429b86f2296ce6f584f42d8b73c75e54bfdabc3980eccb86664de70
7
+ data.tar.gz: 9e445c44aefdec481115e3a9f54bd38b5ac0f42e34e904c2f31928ceebb85a4cfb88e7a9e0525e9fc272c30b6a459c429b8bd70f946c4cc918e9f63120131699
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem "coveralls", require: false
7
+ gem 'coveralls', require: false
8
8
  end
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`).
@@ -1,5 +1,6 @@
1
- require "hash_op/version"
1
+ require 'hash_op/version'
2
2
 
3
+ # Namespacing module
3
4
  module HashOp
4
5
  end
5
6
 
@@ -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, 'First argument must be an Hash' unless hash.is_a?(Hash)
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
- raise 'Invalid attribute, must be a String or an Array'
26
+ fail ArgumentError, 'Invalid attribute, must be a String or an Array'
27
27
  end
28
28
  end
29
29
  module_function :fetch
@@ -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
- # Check the README for examples.
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
@@ -1,4 +1,6 @@
1
1
  require 'hash_op/deep'
2
+ require 'hash_op/grouping'
3
+ require 'hash_op/merge'
2
4
 
3
5
  # A set of functions to perform mathematical operations
4
6
  # on Hashes.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module HashOp
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.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-09-12 00:00:00.000000000 Z
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: []