recollect-array 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +10 -0
- data/lib/recollect/array/filterable.rb +55 -14
- data/lib/recollect/array/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fbfc110c1d152ac717818073bfd1992075a2f661e0476fb914dcf9082436745
|
4
|
+
data.tar.gz: 45faef709c5d1f123a3f1aae9f45efc877fb34d5638dacc73de766cb2c4e5333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbefed9321cf4c56854090598fff906ddd4dff5c7ba8ddaab71bc606e7d41a1b87c0cf0783d0ef8ec8bd80c40b15e7f7322e3c6163b776eef61ca91823cd31bd
|
7
|
+
data.tar.gz: a6cff58f1fa350d046ce25c24de264f49f79bf9422902e266349aadfe70df7852b684cfea028a407422fe6babf68113b55dc77053a1a06024b6a9c0428f95d6f
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2
|
data/README.md
CHANGED
@@ -196,6 +196,16 @@ filters = {
|
|
196
196
|
collection = Recollect::Array.filter(data, filters)
|
197
197
|
```
|
198
198
|
|
199
|
+
Using default Equal predicate.
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
Recollect::Array.filter(data, numbers: 3)
|
203
|
+
|
204
|
+
Recollect::Array.filter(data, active: true)
|
205
|
+
|
206
|
+
Recollect::Array.filter(data, id: 3)
|
207
|
+
```
|
208
|
+
|
199
209
|
If array, you can navigate into self, using `property.NUMBER.property`
|
200
210
|
|
201
211
|
```ruby
|
@@ -9,6 +9,28 @@ module Recollect
|
|
9
9
|
instance
|
10
10
|
end
|
11
11
|
|
12
|
+
PREDICATES = %w[
|
13
|
+
eq
|
14
|
+
noteq
|
15
|
+
not_eq
|
16
|
+
cont
|
17
|
+
notcont
|
18
|
+
not_cont
|
19
|
+
lt
|
20
|
+
lteq
|
21
|
+
gt
|
22
|
+
gteq
|
23
|
+
start
|
24
|
+
notstart
|
25
|
+
not_start
|
26
|
+
end
|
27
|
+
notend
|
28
|
+
not_end
|
29
|
+
in
|
30
|
+
notin
|
31
|
+
not_in
|
32
|
+
].freeze
|
33
|
+
|
12
34
|
# Available filter
|
13
35
|
attr_accessor :filters
|
14
36
|
|
@@ -30,23 +52,30 @@ module Recollect
|
|
30
52
|
|
31
53
|
case value
|
32
54
|
when ::Hash
|
33
|
-
value.each do |predicate,
|
55
|
+
value.each do |predicate, hash_value|
|
34
56
|
klass = Predicate.call(predicate)
|
35
57
|
|
36
58
|
@result.filter! do |item|
|
37
|
-
case
|
59
|
+
case hash_value
|
38
60
|
when Proc, Module
|
39
|
-
klass.check!(item, key,
|
61
|
+
klass.check!(item, key, hash_value.call)
|
40
62
|
else
|
41
|
-
klass.check!(item, key,
|
63
|
+
klass.check!(item, key, hash_value)
|
42
64
|
end
|
43
65
|
end
|
44
66
|
end
|
45
67
|
else
|
46
68
|
parts = key.to_s.split('_')
|
47
|
-
|
69
|
+
|
70
|
+
predicate = Array(parts[-2..]).filter do |pkey|
|
71
|
+
next unless PREDICATES.include? pkey
|
72
|
+
|
73
|
+
parts = parts - [pkey]
|
74
|
+
pkey
|
75
|
+
end&.last || :eq
|
76
|
+
|
48
77
|
iteratee = parts.join('_')
|
49
|
-
klass = Predicate.call(predicate
|
78
|
+
klass = Predicate.call(predicate)
|
50
79
|
|
51
80
|
next unless !!klass
|
52
81
|
|
@@ -61,14 +90,26 @@ module Recollect
|
|
61
90
|
|
62
91
|
Predicate = lambda do |named|
|
63
92
|
{
|
64
|
-
eq: Equal,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
93
|
+
eq: Equal,
|
94
|
+
noteq: NotEqual,
|
95
|
+
not_eq: NotEqual,
|
96
|
+
cont: Contains,
|
97
|
+
notcont: NotContains,
|
98
|
+
not_cont: NotContains,
|
99
|
+
lt: LessThan,
|
100
|
+
lteq: LessThanEqual,
|
101
|
+
gt: GreaterThan,
|
102
|
+
gteq: GreaterThanEqual,
|
103
|
+
start: Startify,
|
104
|
+
notstart: NotStartify,
|
105
|
+
not_start: NotStartify,
|
106
|
+
end: Endify,
|
107
|
+
notend: NotEndify,
|
108
|
+
not_end: NotEndify,
|
109
|
+
in: Included,
|
110
|
+
notin: NotIncluded,
|
111
|
+
not_in: NotIncluded
|
112
|
+
}[named.to_sym || :eq]
|
72
113
|
end
|
73
114
|
private_constant :Predicate
|
74
115
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recollect-array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thadeu Esteves
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-02-28 00:00:00.000000000 Z
|
@@ -131,7 +131,7 @@ homepage: https://github.com/thadeu/recollect-array
|
|
131
131
|
licenses:
|
132
132
|
- MIT
|
133
133
|
metadata: {}
|
134
|
-
post_install_message:
|
134
|
+
post_install_message:
|
135
135
|
rdoc_options: []
|
136
136
|
require_paths:
|
137
137
|
- lib
|
@@ -146,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
150
|
-
signing_key:
|
149
|
+
rubygems_version: 3.3.7
|
150
|
+
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Simple wrapper to filter array using Ruby and simple predicate conditions
|
153
153
|
test_files: []
|