data_filter 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +7 -0
- data/lib/data_filter/filter_set.rb +3 -2
- data/lib/data_filter/like_filter.rb +6 -3
- data/lib/data_filter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 423634bead5abf11f4605f85c5e79d48820a1e4d
|
4
|
+
data.tar.gz: 13334a917228b435cb40c341b2c507ed1ee32c06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e15149b97833c4b4229482abd1d7888255621854d3cec6136324bd6fe81b9e73d32de444d687ad55c551b0066a93201999c42480968dc0bb80d34abaa99d06b
|
7
|
+
data.tar.gz: ba2054ce610b9c4d12566aa95fb29af6360ce6059ef00db0f5b25be0c050e0bcec4e3502a9dbc5496c167832d616203b3ef1940d476949a861582cf3e56c3c24
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,9 @@ filter_set = DataFilter::FilterSet.create do
|
|
30
30
|
# Fuzzy comparison
|
31
31
|
like_filter :name, by: params[:name]
|
32
32
|
|
33
|
+
# Fuzzy comparison with custom normalization
|
34
|
+
like_filter :name, by: params[:name], normalize_regex: /[^\w\s^@^.^+^-]/
|
35
|
+
|
33
36
|
# Keyword search
|
34
37
|
keyword_filter [:gender], by: params[:gender]
|
35
38
|
|
@@ -58,6 +61,10 @@ filter_set.call(data)
|
|
58
61
|
## Changelog
|
59
62
|
|
60
63
|
```
|
64
|
+
* v0.4.0
|
65
|
+
|
66
|
+
- Added :normalize_regex option to LikeFilter
|
67
|
+
|
61
68
|
* v0.3.1
|
62
69
|
|
63
70
|
- Extend DSL with PrefixFilter
|
@@ -91,10 +91,11 @@ module DataFilter
|
|
91
91
|
# @param field_sym [Symbol] name of the data method we want
|
92
92
|
# to filter
|
93
93
|
# @option opts [Object] :by the value we want to use when
|
94
|
-
# filtering the data item
|
94
|
+
# filtering the data item, :normalize_regex the regular
|
95
|
+
# expression used to normalize the string
|
95
96
|
def like_filter(field_sym, opts = {})
|
96
97
|
if opts[:by]
|
97
|
-
@filters << LikeFilter.new(field_sym, opts[:by])
|
98
|
+
@filters << LikeFilter.new(field_sym, opts[:by], opts[:normalize_regex])
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
@@ -12,9 +12,12 @@ module DataFilter
|
|
12
12
|
# to filter
|
13
13
|
# @param search_term [String] the value we want to use when
|
14
14
|
# filtering the data item
|
15
|
-
|
15
|
+
# @param normalize_regex [regex] the optional regular
|
16
|
+
# expression for normalizing the string to search
|
17
|
+
def initialize(field_sym, search_term, normalize_regex = /[^\w\s]/)
|
16
18
|
@field_sym = field_sym
|
17
19
|
@search_term = search_term
|
20
|
+
@normalize_regex = normalize_regex
|
18
21
|
end
|
19
22
|
|
20
23
|
# Filters the item
|
@@ -52,9 +55,9 @@ module DataFilter
|
|
52
55
|
def normalize(str, use_cache = false)
|
53
56
|
if use_cache
|
54
57
|
@normalize_cache ||= {}
|
55
|
-
@normalize_cache[str] ||= str.gsub(
|
58
|
+
@normalize_cache[str] ||= str.gsub(@normalize_regex, ' ')
|
56
59
|
else
|
57
|
-
str.gsub(
|
60
|
+
str.gsub(@normalize_regex, ' ')
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/lib/data_filter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Bodah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.5.1
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: an extensible DSL for filtering data sets
|