recollect-array 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: b0e4b341fd0128d11eebe856242f5a58e4fe2fde5d52a1b32e5ab7677cb87eb0
4
- data.tar.gz: 9dd9dfb0d30ea7d4a5005f9abda3e2123a6716f52bc7e8b65b4ab4e1b7f2909d
3
+ metadata.gz: 5fbfc110c1d152ac717818073bfd1992075a2f661e0476fb914dcf9082436745
4
+ data.tar.gz: 45faef709c5d1f123a3f1aae9f45efc877fb34d5638dacc73de766cb2c4e5333
5
5
  SHA512:
6
- metadata.gz: f456880a49863da46af5ddf3776a6f3997141207b42b4f327235f9498ce78ad65d056eb20794f8bb690ee6f86a3e4084c947cf186319fc2e3b7d2a5f5eb87127
7
- data.tar.gz: 790347aba973043fd253fb00eff346421c7eb263c0672d3e991b33eaf03ec5a04ea0ea1d0d24a87fb54caf11683bdc698fb395e96718a2130c2ef149fd581607
6
+ metadata.gz: dbefed9321cf4c56854090598fff906ddd4dff5c7ba8ddaab71bc606e7d41a1b87c0cf0783d0ef8ec8bd80c40b15e7f7322e3c6163b776eef61ca91823cd31bd
7
+ data.tar.gz: a6cff58f1fa350d046ce25c24de264f49f79bf9422902e266349aadfe70df7852b684cfea028a407422fe6babf68113b55dc77053a1a06024b6a9c0428f95d6f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
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,21 +52,28 @@ module Recollect
30
52
 
31
53
  case value
32
54
  when ::Hash
33
- value.each do |predicate, item_value|
55
+ value.each do |predicate, hash_value|
34
56
  klass = Predicate.call(predicate)
35
57
 
36
58
  @result.filter! do |item|
37
- case item_value
59
+ case hash_value
38
60
  when Proc, Module
39
- klass.check!(item, key, item_value.call)
61
+ klass.check!(item, key, hash_value.call)
40
62
  else
41
- klass.check!(item, key, item_value)
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
- predicate = parts.size == 1 ? :eq : parts.pop
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
78
  klass = Predicate.call(predicate)
50
79
 
@@ -61,13 +90,25 @@ module Recollect
61
90
 
62
91
  Predicate = lambda do |named|
63
92
  {
64
- eq: Equal, noteq: NotEqual, not_eq: NotEqual,
65
- cont: Contains, notcont: NotContains, not_cont: NotContains,
66
- lt: LessThan, lteq: LessThanEqual,
67
- gt: GreaterThan, gteq: GreaterThanEqual,
68
- start: Startify, notstart: NotStartify, not_start: NotStartify,
69
- end: Endify, notend: NotEndify, not_end: NotEndify,
70
- in: Included, notin: NotIncluded, not_in: NotIncluded
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
71
112
  }[named.to_sym || :eq]
72
113
  end
73
114
  private_constant :Predicate
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Recollect
4
4
  module Array
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  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.2
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.1.4
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: []