trick_bag 0.51.0 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 137cb6576cfd3498b7762313918781e053f12550
4
- data.tar.gz: bf7a7e5a71cae9c08a7f8bde90801e422fe63d0a
3
+ metadata.gz: 1d5d7bf7f9d42de360c17f2c0086fb8d4e5286c8
4
+ data.tar.gz: 7fe3d0612c0354ae7e44b539f08aeb5610d1ec2f
5
5
  SHA512:
6
- metadata.gz: 137370f1acfd51c9378894c6328852013c22c3cb522cd1d93033350cd3145197d4b75c7288f7712af42d21411d92300459eb7a01675f9d4b2d5bb678a8bf9684
7
- data.tar.gz: e097d5e75037f2219d8f76c8172afd31ae81a734bbf84dc9860c42b1884a671508c7b73d4b7d4688f7eb02698c5530b4f9a68f12cbbc805a787c5eed51d7f190
6
+ metadata.gz: 18df24c9efffab6eb3f515f2a041f36ac168d6eee769a0482899d147652d41c14b4453e8f244ebff19663ae65ec2ab9a9e2a493cf77508e49d95c66f976df7d6
7
+ data.tar.gz: 6def0aeb779f614446b072f68dffcea124a53fbaa5a3fb22a9f77845fe67712a793b7bb1a15f98113db02faa15a8441758e62fe171eb69c8a0a2dc6af35f76c4
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.52.0
2
+
3
+ * Added RegexValidations.
4
+
5
+
1
6
  ## v0.51.0
2
7
 
3
8
  * Add CollectionAccess access and accessor methods.
@@ -0,0 +1,31 @@
1
+ module TrickBag
2
+ module Validations
3
+
4
+ module_function
5
+
6
+
7
+ # @return whether or not the passed string matches *any* of the regexes in the passed array
8
+ # @param regexes array of regexes to test against
9
+ # @param string the string to test against the regexes
10
+ def matches_any_regex?(regexes, string)
11
+ regexes.any? { |regex| regex === string }
12
+ end
13
+
14
+
15
+ # @return whether or not the passed string matches *all* of the regexes in the passed array
16
+ # @param regexes array of regexes to test against
17
+ # @param string the string to test against the regexes
18
+ def matches_all_regexes?(regexes, string)
19
+ regexes.all? { |regex| regex === string }
20
+ end
21
+
22
+
23
+ # @return whether or not the passed string matches *none* of the regexes in the passed array
24
+ # @param regexes array of regexes to test against
25
+ # @param string the string to test against the regexes
26
+ def matches_no_regexes?(regexes, string)
27
+ regexes.none? { |regex| regex === string }
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = "0.51.0"
2
+ VERSION = "0.52.0"
3
3
  end
@@ -17,11 +17,13 @@ describe CollectionAccess do
17
17
 
18
18
  it 'works with 2 keys' do
19
19
  h = { 'a' => { 'b' => 234 }}
20
+ # instead of h['a']['b']:
20
21
  expect(CollectionAccess.access(h, 'a.b')).to eq(234)
21
22
  end
22
23
 
23
24
  it 'works with 3 keys' do
24
25
  h = { 'a' => { 'bb' => { 'ccc' => 345 }}}
26
+ # instead of h['a']['bb']['ccc']:
25
27
  expect(CollectionAccess.access(h, 'a.bb.ccc')).to eq(345)
26
28
  end
27
29
 
@@ -0,0 +1,54 @@
1
+ require_relative '../../spec_helper.rb'
2
+
3
+ require 'trick_bag/validations/regex_validations'
4
+
5
+ module TrickBag
6
+
7
+ describe Validations do
8
+
9
+ include Validations
10
+
11
+ let(:regexes) { [/a/, /m/, /z/] }
12
+
13
+ context '#matches_any_regex?' do
14
+
15
+ it 'should return true on any match' do
16
+ expect(matches_any_regex?(regexes, 'a')).to eq(true)
17
+ end
18
+
19
+ it 'should return false on no match' do
20
+ expect(matches_any_regex?(regexes, 'b')).to eq(false)
21
+ end
22
+
23
+ end
24
+
25
+
26
+ context '#matches_all_regexes?' do
27
+
28
+ it 'should return true on match all' do
29
+ expect(matches_all_regexes?(regexes, 'amz')).to eq(true)
30
+ end
31
+
32
+ it 'should return false on no match or match some' do
33
+ expect(matches_all_regexes?(regexes, 'b')).to eq(false)
34
+ expect(matches_all_regexes?(regexes, 'am')).to eq(false)
35
+ end
36
+
37
+ end
38
+
39
+
40
+ context '#matches_no_regexes?' do
41
+
42
+ it 'should return true on match' do
43
+ expect(matches_no_regexes?(regexes, 'bny')).to eq(true)
44
+ end
45
+
46
+ it 'should return false on any or all matches' do
47
+ expect(matches_no_regexes?(regexes, 'a')).to eq(false)
48
+ expect(matches_no_regexes?(regexes, 'amz')).to eq(false)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -119,6 +119,7 @@ files:
119
119
  - lib/trick_bag/validations/hash_validations.rb
120
120
  - lib/trick_bag/validations/object_validations.rb
121
121
  - lib/trick_bag/validations/other_validations.rb
122
+ - lib/trick_bag/validations/regex_validations.rb
122
123
  - lib/trick_bag/version.rb
123
124
  - spec/spec_helper.rb
124
125
  - spec/trick_bag/collections/collection_access_spec.rb
@@ -144,6 +145,7 @@ files:
144
145
  - spec/trick_bag/validations/hash_validations_spec.rb
145
146
  - spec/trick_bag/validations/object_validations_spec.rb
146
147
  - spec/trick_bag/validations/other_validations_spec.rb
148
+ - spec/trick_bag/validations/regex_validations_spec.rb
147
149
  - trick_bag.gemspec
148
150
  homepage: https://github.com/keithrbennett/trick_bag
149
151
  licenses:
@@ -194,3 +196,4 @@ test_files:
194
196
  - spec/trick_bag/validations/hash_validations_spec.rb
195
197
  - spec/trick_bag/validations/object_validations_spec.rb
196
198
  - spec/trick_bag/validations/other_validations_spec.rb
199
+ - spec/trick_bag/validations/regex_validations_spec.rb