hamstar 0.0.7 → 0.0.8

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: ab040a250a4325cf3681baf92ff97430166dbecb
4
- data.tar.gz: 1d7031c670edffa37f16fda7c9e47f0b70b39f75
3
+ metadata.gz: 080ce403676cf58160a805b76098674a414b20e2
4
+ data.tar.gz: 875e04443ada66d1eb1cc79f07117cb2e1d71bc4
5
5
  SHA512:
6
- metadata.gz: 232b3941196abc177f5586ea0e52f4c64b46543639a3a429b2fd36925a317deac862327d5fa35f639f4c1d5d1fbf3e54df28332adddbb4c98fb4cf2ec9f184b0
7
- data.tar.gz: 6aa7d473b7bae0b839d9f58cd3846eef3f0eb03660b36218705573dd55920762d4cb956db3469574be3a45a9f2f2d75094494c821ac27b5b5703f3462beab528
6
+ metadata.gz: 88bd7039e6d77342821c2965757d52c353d187cc0254032bc307a0868bcecb4edcdbe276187840f4634eaaf94d94afd092cddeec650f8b4386c19c845cb10634
7
+ data.tar.gz: 3a96805cba6afd746d3b152157b1f11a0052669353db4d2c708effd3f7cfa98c4a008369692532841db985258ec5d0df0b97c6543497f49c8c8f0424bda469cb
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  `Hamstar.update_having` is a `module_function` that works just like [Hamster update_in()](https://github.com/hamstergem/hamster#transformations) but with three additional ways to select container elements:
4
4
 
5
- 1. the associative selector denoted by an array containing a key and a value e.g. `[:name,'Chris']`
6
- 2. the Kleene star operator denoted by '*'
5
+ 1. the Kleene star operator denoted by `'*'`
6
+ 2. the associative selector denoted by an array containing a key and a value e.g. `[:name,'Chris']` your values will be compared to this one using the case comparison operator `===` so you can use Strings or regexps or other things that define `===` (such as classes and Ranges)
7
7
  3. generalized `Proc`-based matching e.g. you can supply a lambda directly in the path specification
8
8
 
9
9
  ## Installation
@@ -53,10 +53,17 @@ Hamstar.update_having( x, [:name,'Pat'],:name){|name| 'Patsy'}
53
53
  => Hamster::Vector[Hamster::Hash[:name => "Chris", :hobbies => Hamster::Vector["clarinet"]], Hamster::Hash[:name => "Patsy", :hobbies => Hamster::Vector["bird watching", "rugby"]]]
54
54
  ```
55
55
 
56
- Finally, you can use a `Proc` as a matcher. Here's an example that supplies a lambda inline:
56
+ Note that your values will be compared to the second element of the pair using the case comparison operator `===`. That means you can use a Regexp there (or any other object that defines `===`) e.g.:
57
57
 
58
58
  ```ruby
59
- Hamstar.update_having( x, ->(k,v){v[:name] == 'Pat'},:name){|name| 'Patsy'}
59
+ Hamstar.update_having( x, [:name,/P/],:name){|name| name+'sy'}
60
+ => (same result as before)
61
+ ```
62
+
63
+ Finally, if none of the options given above work for you, you can use an arbitrary `Proc` as a matcher. Here's an example that supplies a lambda inline:
64
+
65
+ ```ruby
66
+ Hamstar.update_having( x, ->(k,v){k.odd?},:name){|name| 'Patsy'}
60
67
  => Hamster::Vector[Hamster::Hash[:name => "Chris", :hobbies => Hamster::Vector["clarinet"]], Hamster::Hash[:name => "Patsy", :hobbies => Hamster::Vector["bird watching", "rugby"]]]
61
68
  ```
62
69
 
@@ -15,7 +15,7 @@ module Hamstar
15
15
  matcher = match_path[0]
16
16
  case matcher
17
17
  when KLEENE_STAR; match ->(k,v){true}, c, *match_path, &block
18
- when Array, Hamster::Vector; match ->(k,v){key,value=matcher; v[key] == value}, c, *match_path, &block
18
+ when Array, Hamster::Vector; match ->(k,v){key,value=matcher; value === v[key]}, c, *match_path, &block
19
19
  when Proc; match matcher, c, *match_path, &block
20
20
  else
21
21
  if match_path.size == 1
@@ -32,7 +32,7 @@ module Hamstar
32
32
  mp_rest = Hamster.from(match_path)[1..-1] # drop first expr
33
33
  c.each_pair do |key,value|
34
34
  if matcher.call key, value
35
- mp = mp_rest.unshift key # put key where assoc was
35
+ mp = mp_rest.unshift key # put key where expr was
36
36
  c = update_having c, *mp, &block
37
37
  end
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module Hamstar
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -19,9 +19,12 @@ RSpec.describe Hamstar do
19
19
  [ [{a:1},{a:2}],['*',:a], ->(v){v+1}, [{a:2},{a:3}], 'Hash inside Vector']
20
20
  ]
21
21
 
22
+ cph = [{name:'Chris'},{name:'Pat'}]
23
+ addsy = ->(name){name+'sy'}
22
24
  examples_associative = [
23
- [ [{name:'Chris'},{name:'Pat'}], [[:name,'Pat'],:name],->(name){name+'sy'}, [{name:'Chris'},{name:'Patsy'}], 'match a Hash'],
24
- [ [[:name,'Chris'],[:name,'Pat']],[[1,'Pat'],1], ->(name){name+'sy'}, [[:name,'Chris'],[:name,'Patsy']],'match a Vector']
25
+ [ cph, [[:name,'Pat'],:name], addsy, [{name:'Chris'},{name:'Patsy'}], 'match a Hash'],
26
+ [ [[:name,'Chris'],[:name,'Pat']],[[1,'Pat'],1], addsy, [[:name,'Chris'],[:name,'Patsy']],'match a Vector'],
27
+ [ cph, [[:name,/P/],:name], addsy, [{name:'Chris'},{name:'Patsy'}], 'match a Hash w/ a regexp']
25
28
  ]
26
29
 
27
30
  examples_function_match = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamstar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Burcham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamster