recollect-array 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c60eb4e7c1f4cdbb94be9a3dd9cf0118a990e6b0aea89e238b32490a8557354
4
- data.tar.gz: 4f8a4c8f5311d192e62cc539fdc5bf4274fed94def9ee3e3ea524de7e02a7dc4
3
+ metadata.gz: 5fbfc110c1d152ac717818073bfd1992075a2f661e0476fb914dcf9082436745
4
+ data.tar.gz: 45faef709c5d1f123a3f1aae9f45efc877fb34d5638dacc73de766cb2c4e5333
5
5
  SHA512:
6
- metadata.gz: fb8f5e5fa178a2981d77f79d3727889062ffbce756b3dc354c50e62fe42df51c8bed60b20cfbd196127b06ea5222e25ec9d42bee2e95577bf5b901a6a6474029
7
- data.tar.gz: 60d86ca9e454898bc7cc981eafc80a7e2411a326141ee291dea52f4c39ca83e96719ffb11ec96e4195c6189f4a2f54298b0c888516827a574ff8356acfcff25b
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,23 +52,30 @@ 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.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
- klass = Predicate.call(predicate || 'eq')
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, 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
71
- }[named.to_sym]
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Recollect
4
4
  module Array
5
- VERSION = '0.1.1'
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.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.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: []