trick_bag 0.52.0 → 0.53.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10d48447cbfae946c5031fe4185b8f6e9b32db40
|
4
|
+
data.tar.gz: efbf46ebee805589444309d8152459c7be2aac47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c857c06e68c514fdea178aeb10096c1039a410cffa3f82f6e5307049a9b647bf34b67e6b5136e08a12262bb9708afa7578ffd1e232d56eb56da7daa409a45a4
|
7
|
+
data.tar.gz: 8ea9e60093075ce0289cd64a9da2c6364bf0025fe77d69a74016cdf19851612e54124a311741af89c618a933713954153bb4d31535dd480c5e9de379a547432b
|
data/RELEASE_NOTES.md
CHANGED
@@ -27,5 +27,49 @@ module Validations
|
|
27
27
|
regexes.none? { |regex| regex === string }
|
28
28
|
end
|
29
29
|
|
30
|
+
|
31
|
+
# Analyzes a list of strings and a list of regexes, gathering information
|
32
|
+
# about which regexes match which strings. The to_h method returns
|
33
|
+
# a hash whose keys are the regexes and values are arrays of strings
|
34
|
+
# in the string list that match the regex. Note that if a string matches
|
35
|
+
# multiple regexes, it will be added to the arrays of all the regexes it matched.
|
36
|
+
class RegexStringListAnalyzer
|
37
|
+
|
38
|
+
attr_reader :regex_strings_hash
|
39
|
+
|
40
|
+
def initialize(regexes, strings)
|
41
|
+
@regex_strings_hash = regexes.each_with_object({}) do |regex, match_hash|
|
42
|
+
match_hash[regex] = []
|
43
|
+
end
|
44
|
+
strings.each do |string|
|
45
|
+
regexes_matched = regexes.select { |regex| regex === string }
|
46
|
+
regexes_matched.each do |regex_matched|
|
47
|
+
regex_strings_hash[regex_matched] << string
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Returns a hash whose keys are the regexes, and the values are the
|
54
|
+
# strings that matched the regex key.
|
55
|
+
def to_h
|
56
|
+
@regex_strings_hash
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Takes a match hash returned by the match_hash method above,
|
61
|
+
# and returns the regexes for which no matches were found.
|
62
|
+
def regexes_without_matches
|
63
|
+
regex_strings_hash.keys.select { |key| regex_strings_hash[key].empty? }
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Takes a match hash returned by the match_hash method above,
|
68
|
+
# and returns the regexes for which matches were found.
|
69
|
+
def regexes_with_matches
|
70
|
+
regex_strings_hash.keys.reject { |key| regex_strings_hash[key].empty? }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
30
74
|
end
|
31
75
|
end
|
data/lib/trick_bag/version.rb
CHANGED
@@ -49,6 +49,30 @@ module TrickBag
|
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
52
|
+
|
53
|
+
|
54
|
+
context 'RegexStringListAnalyzer' do
|
55
|
+
|
56
|
+
expected_hash = { /a/ => %w(apple mango), /m/ => ['mango'], /z/ => [] }
|
57
|
+
|
58
|
+
subject do
|
59
|
+
strings = %w(apple mango)
|
60
|
+
TrickBag::Validations::RegexStringListAnalyzer.new(regexes, strings)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should return a correct hash' do
|
64
|
+
expect(subject.to_h).to eq(expected_hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return the correct array of NONmatches' do
|
68
|
+
expect(subject.regexes_without_matches).to eq([/z/])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return the correct array of matches' do
|
72
|
+
expect(subject.regexes_with_matches).to eq([/a/, /m/])
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
52
76
|
end
|
53
77
|
end
|
54
78
|
|
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.
|
4
|
+
version: 0.53.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-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: os
|