Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit f2d95fc

Browse files
committed
👌🏼 rename library
1 parent d592f00 commit f2d95fc

26 files changed

+477
-213
lines changed

README.md

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<p align="center">
2-
<h1 align="center">㌨ nano-collection-filter</h1>
3-
<p align="center"><i>Simple wrapper to filter array using Pure Ruby and conditions</i></p>
2+
<h1 align="center">🔃 recollect-array-filter</h1>
3+
<p align="center"><i>Simple wrapper to filter array using Ruby and simple predicate conditions</i></p>
44
</p>
55

66
<p align="center">
7-
<a href="https://rubygems.org/gems/nano-collection-filter">
8-
<img alt="Gem" src="https://img.shields.io/gem/v/nano-collection-filter.svg?style=flat-square">
7+
<a href="https://rubygems.org/gems/recollect-array-filter">
8+
<img alt="Gem" src="https://img.shields.io/gem/v/recollect-array-filter.svg?style=flat-square">
99
</a>
1010

11-
<a href="https://github.com/thadeu/nano-collection-filter/actions/workflows/ci.yml">
12-
<img alt="Build Status" src="https://github.com/thadeu/nano-collection-filter/actions/workflows/ci.yml/badge.svg">
11+
<a href="https://github.com/thadeu/recollect-array-filter/actions/workflows/ci.yml">
12+
<img alt="Build Status" src="https://github.com/thadeu/recollect-array-filter/actions/workflows/ci.yml/badge.svg">
1313
</a>
1414
</p>
1515

@@ -22,13 +22,14 @@ Because in sometimes, we need filter array passing conditions. This gem simplify
2222

2323
Version | Documentation
2424
---------- | -------------
25-
unreleased | https://github.com/thadeu/nano-collection-filter/blob/main/README.md
25+
unreleased | https://github.com/thadeu/recollect-array-filter/blob/main/README.md
2626

2727
## Table of Contents <!-- omit in toc -->
2828
- [Installation](#installation)
29-
- [Usage](#usage)
3029
- [Configuration](#configuration)
3130
- [Availables Predicates](#availables-predicates)
31+
- [Usage](#usage)
32+
- [Utilities](#utilities)
3233

3334
## Compatibility
3435

@@ -38,10 +39,16 @@ unreleased | https://github.com/thadeu/nano-collection-filter/blob/main/README.m
3839

3940
## Installation
4041

41-
Add this line to your application's Gemfile.
42+
Use bundle
4243

4344
```ruby
44-
gem 'nano-collection-filter', '~> 0.0.1'
45+
bundle add recollect-array-filter
46+
```
47+
48+
or add this line to your application's Gemfile.
49+
50+
```ruby
51+
gem 'recollect-array-filter'
4552
```
4653

4754
## Configuration
@@ -71,7 +78,7 @@ Without configuration, because we use only Ruby. ❤️
7178
## Usage
7279

7380
<details>
74-
<summary>Data</summary>
81+
<summary>Think that your data seems like this.</summary>
7582

7683
```ruby
7784
data = [
@@ -106,29 +113,30 @@ Without configuration, because we use only Ruby. ❤️
106113
```
107114
</details>
108115

116+
So, you can use many predicate to filter array. For example:
109117

110118
## Equal
111119

112120
```ruby
113121
filters = { active_eq: true }
114122

115-
collection = Nano::Collection::Search.apply(data, filters)
123+
collection = Recollect::Array.filter(data, filters)
116124
```
117125

118126
## NotEqual
119127

120128
```ruby
121129
filters = { active_noteq: true }
122130

123-
collection = Nano::Collection::Search.apply(data, filters)
131+
collection = Recollect::Array.filter(data, filters)
124132
```
125133

126134
## Nested Hash Paths
127135

128136
```ruby
129137
filters = { 'schedule.all_day_eq': false }
130138

131-
collection = Nano::Collection::Search.apply(data, filters)
139+
collection = Recollect::Array.filter(data, filters)
132140
```
133141

134142
## Nested Array Paths
@@ -138,19 +146,22 @@ collection = Nano::Collection::Search.apply(data, filters)
138146
```ruby
139147
filters = { 'numbers.0_eq': '3' }
140148

141-
collection = Nano::Collection::Search.apply(data, filters)
149+
collection = Recollect::Array.filter(data, filters)
142150
```
143151

144152
```ruby
145153
filters = { numbers_in: ['1'] }
146154

147-
collection = Nano::Collection::Search.apply(data, filters)
155+
collection = Recollect::Array.filter(data, filters)
148156

149157
expect(collection.result.size).to eq(1)
150158
```
151159

152160
## Combine conditions
153161

162+
Yes, you can combine one or multiple predicates to filter you array.
163+
164+
154165
```ruby
155166
filters = {
156167
active_noteq: true,
@@ -159,7 +170,66 @@ filters = {
159170
'schedule.all_day_eq': false
160171
}
161172

162-
collection = Nano::Collection::Search.apply(data, filters)
173+
collection = Recollect::Array.filter(data, filters)
174+
```
175+
176+
## Utilities
177+
178+
### Recollect::Hash.get(hash, path)
179+
180+
```ruby
181+
user = {
182+
id: 1,
183+
name: 'Test #1',
184+
email: 'test1@email1.com',
185+
schedule: { all_day: true },
186+
numbers: %w[1 2],
187+
active: true,
188+
count: 9
189+
}
190+
191+
result = Recollect::Hash.get(user, 'id')
192+
-> 1
193+
194+
result = Recollect::Hash.get(user, 'schedule.all_day')
195+
-> true
196+
197+
result = Recollect::Hash.get(user, 'numbers')
198+
-> ['1', '2']
199+
200+
result = Recollect::Hash.get(user, 'numbers.0')
201+
-> 1
202+
```
203+
204+
### Recollect::Array.pluck(array, path)
205+
206+
```ruby
207+
users = [
208+
{
209+
id: 1,
210+
name: 'Test #1',
211+
email: 'test1@email1.com',
212+
schedule: { all_day: true },
213+
numbers: %w[1 2],
214+
active: true,
215+
count: 9
216+
},
217+
{
218+
id: 2,
219+
name: 'Test #1',
220+
email: 'test1@email1.com',
221+
schedule: { all_day: true },
222+
numbers: %w[1 2],
223+
active: true,
224+
count: 9
225+
}
226+
]
227+
228+
result = Recollect::Array.pluck(users, 'id')
229+
$ -> [1, 2]
230+
231+
result = Recollect::Array.pluck(users, 'schedule.all_day')
232+
$ -> [true, true]
163233
```
164234

165235
[⬆️ &nbsp;Back to Top](#table-of-contents-)
@@ -172,13 +242,9 @@ To install this gem onto your local machine, run `bundle install`. To release a
172242

173243
## Contributing
174244

175-
Bug reports and pull requests are welcome on GitHub at https://github.com/thadeu/nano-collection-filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/thadeu/nano-collection-filter/blob/master/CODE_OF_CONDUCT.md).
245+
Bug reports and pull requests are welcome on GitHub at https://github.com/thadeu/recollect-array-filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/thadeu/recollect-array-filter/blob/master/CODE_OF_CONDUCT.md).
176246

177247

178248
## License
179249

180250
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
181-
182-
## Contributing
183-
184-
We have a long list of valued contributors. Check them all at: https://github.com/thadeu/nano-collection-filter.

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
require 'bundler/setup'
5-
require 'nano'
5+
require 'recollect'
66

77
# You can add fixtures and/or initialization code here to make experimenting
88
# with your gem easier. You can also use a different console, if you like.

lib/nano.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/nano/collection/search.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

lib/nano/hash/helpers.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/recollect.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Recollect
4+
require_relative 'recollect/predicate/startify'
5+
require_relative 'recollect/predicate/endify'
6+
require_relative 'recollect/predicate/equal'
7+
require_relative 'recollect/predicate/contains'
8+
require_relative 'recollect/predicate/in'
9+
require_relative 'recollect/predicate/less_than'
10+
require_relative 'recollect/predicate/greater_than'
11+
12+
require_relative 'recollect/utility'
13+
require_relative 'recollect/hash'
14+
require_relative 'recollect/filterable'
15+
require_relative 'recollect/array'
16+
end

0 commit comments

Comments
 (0)