{"id":15471881,"url":"https://github.com/thadeu/recollect-array","last_synced_at":"2025-10-04T00:31:19.542Z","repository":{"id":81000560,"uuid":"605828432","full_name":"thadeu/recollect-array","owner":"thadeu","description":"🔃 Simple wrapper to filter array using Ruby and simple predicate conditions","archived":false,"fork":false,"pushed_at":"2023-02-28T16:52:17.000Z","size":55,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T23:21:40.263Z","etag":null,"topics":["array","array-filter","array-like","collection-filters","filter","gems","recollect-array","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/recollect-array","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thadeu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-24T01:30:55.000Z","updated_at":"2023-06-03T11:57:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"e49c2c17-3bfe-450f-ab68-b7b707367dd3","html_url":"https://github.com/thadeu/recollect-array","commit_stats":{"total_commits":51,"total_committers":1,"mean_commits":51.0,"dds":0.0,"last_synced_commit":"1b5ee559cba053af7af0cf1eb65f271e74b0d9de"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Frecollect-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Frecollect-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Frecollect-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Frecollect-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thadeu","download_url":"https://codeload.github.com/thadeu/recollect-array/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235204548,"owners_count":18952330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","array-filter","array-like","collection-filters","filter","gems","recollect-array","ruby"],"created_at":"2024-10-02T02:22:07.062Z","updated_at":"2025-10-04T00:31:14.238Z","avatar_url":"https://github.com/thadeu.png","language":"Ruby","readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e🔃 recollect-array\u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\u003ci\u003eSimple wrapper to filter array using Ruby and simple predicate conditions\u003c/i\u003e\u003c/p\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://rubygems.org/gems/recollect-array\"\u003e\n    \u003cimg alt=\"Gem\" src=\"https://img.shields.io/gem/v/recollect-array.svg\"\u003e    \n  \u003c/a\u003e\n\n  \u003ca href=\"https://github.com/thadeu/recollect-array/actions/workflows/ci.yml\"\u003e\n    \u003cimg alt=\"Build Status\" src=\"https://github.com/thadeu/recollect-array/actions/workflows/ci.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n## Motivation\n\nBecause in sometimes, we need filter array passing conditions. This gem simplify this work.\n\n## Documentation \u003c!-- omit in toc --\u003e\n\nVersion    | Documentation\n---------- | -------------\nunreleased | https://github.com/thadeu/recollect-array/blob/main/README.md\n\n## Table of Contents \u003c!-- omit in toc --\u003e\n  - [Installation](#installation)\n  - [Configuration](#configuration)\n  - [Availables Predicates](#availables-predicates)\n  - [Usage](#usage)\n  - [Utilities](#utilities)\n\n## Compatibility\n\n| kind           | branch  | ruby               |\n| -------------- | ------- | ------------------ |\n| unreleased     | main    | \u003e= 2.5.8, \u003c= 3.1.x |\n\n## Installation\n\nUse bundle\n\n```ruby\nbundle add recollect-array\n```\n\nor add this line to your application's Gemfile.\n\n```ruby\ngem 'recollect-array'\n```\n\nand then, require module\n\n```ruby\nrequire 'recollect/array'\n```\n\n## Configuration\n\nWithout configuration, because we use only Ruby. ❤️\n\n## Availables Predicates for all values\n\n| Type | Suffix | Value | \n| ----------- | ----------- | ----------- |\n| Equal | eq      | Anywhere |\n| NotEqual | noteq        | Anywhere |\n| Contains | cont        | Anywhere |\n| NotContains | notcont        | Anywhere |\n| Included | in  | Anywhere |\n| NotIncluded | notin        | Anywhere |\n| Start | start        | Anywhere |\n| NotStart | notstart        | Anywhere |\n| End | end        | Anywhere |\n| NotEnd | notend        | Anywhere |\n| LessThan | lt        | Anywhere |\n| LessThanEqual | lteq        | Anywhere |\n| GreaterThan | gt        | Anywhere |\n| GreaterThanEqual | gteq        | Anywhere |\n\n## Availables Predicates only when value is Hash\n\n\u003e 💡 Below predicates works only when value is Hash\n\n| Type | Suffix | Value | \n| ----------- | ----------- | ----------- |\n| NotEqual | not_eq        | Hash |\n| NotContains | not_cont        | Hash |\n| NotIncluded | not_in        | Hash |\n| NotStart | not_start        | Hash |\n| NotEnd | not_end        | Hash |\n\n\n## Usage\n\n\u003cdetails\u003e\n  \u003csummary\u003eThink that your data seems like this.\u003c/summary\u003e\n  \n  ```ruby\n  data = [\n    {\n      id: 1,\n      name: 'Test #1',\n      email: 'test1@email1.com',\n      schedule: { all_day: true },\n      numbers: %w[1 2],\n      active: true,\n      count: 9\n    },\n    {\n      id: 2,\n      name: 'Test #2',\n      email: 'test2@email2.com',\n      schedule: { all_day: false },\n      numbers: %w[3 4],\n      active: true,\n      count: 10\n    },\n    {\n      id: 3,\n      name: 'Test #3',\n      email: 'test3@email3.com',\n      schedule: { all_day: false },\n      numbers: %w[5 6],\n      active: false,\n      count: 99\n    }\n  ]\n  ```\n\u003c/details\u003e\n\nYou can use one or multiples predicates in your filter. We see some use cases.\n\n### Flexible Use Case (Hash)\n\n**Equal**\n\n```ruby\nfilters = {\n  active: {\n    eq: true\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**NotEqual**\n\n```ruby\nfilters = {\n  active: {\n    # noteq or not_eq\n    not_eq: true\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Nested Hash Paths**\n\n```ruby\nfilters = {\n  'schedule.all_day': {\n    eq: true\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Nested Array Paths**\n\n\u003e Note the `.0` 🎉\n\n```ruby\nfilters = {\n  'numbers.0': {\n    eq: '3'\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n```ruby\nfilters = {\n  numbers: {\n    in: '3' # or in: ['3']\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\nUsing default Equal predicate.\n\n```ruby\nRecollect::Array.filter(data, numbers: 3)\n\nRecollect::Array.filter(data, active: true)\n\nRecollect::Array.filter(data, id: 3)\n```\n\nIf array, you can navigate into self, using `property.NUMBER.property`\n\n```ruby\ndata = [\n  {\n    schedules: [\n      {\n        opened: true,\n        all_day: true\n      },\n      {\n        opened: false,\n        all_day: true\n      }\n    ]\n  },\n  {\n    schedules: [\n      {\n        opened: false,\n        all_day: true\n      },\n      {\n        opened: false,\n        all_day: true\n      }\n    ]\n  }\n]\n\nfilters = {\n  'schedules.0.opened': {\n    eq: true\n  }\n}\n\n# OR\n\nfilters = {\n  'schedules[0]opened': {\n    eq: true\n  }\n}\n\n# OR\n\nfilters = {\n  'schedules.[0].opened': {\n    eq: true\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n\n# [{ schedules: [{ opened: true, all_day: true }, { opened: false, all_day: true }] }]\n```\n\nAmazing, you can pass a Callable value as value, like this.\n\n```ruby\nfilters = {\n  'schedules.[0].opened': {\n    eq: -\u003e { true }\n  }\n}\n\n# OR a Module\n\nmodule ActiveTruthy\n  def self.call = true\nend\n\nmodule NumbersAvailable\n  def self.call = %w[1 2]\nend\n\nfilters = {\n  'schedules.[0].opened': {\n    eq: ActiveTruthy\n  },\n  numbers: {\n    in: NumbersAvailable\n  }\n}\n\n# OR a Class\n\nclass ActiveFalsey\n  def self.call = false\nend\n\nfilters = {\n  'schedules.[0].opened': {\n    eq: ActiveFalsey\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Combine conditions**\n\nYes, you can combine one or multiple predicates to filter you array.\n\n\n```ruby\nfilters = {\n  active: { eq: true },\n  numbers: {\n    in: %w[5],\n    not_in: '10'\n  },\n  email: {\n    cont: 'email1',\n    not_cont: '@gmail'\n  },\n  'schedule.all_day': {\n    in: [true, false]\n  }\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n### Querystring Use Case\n\n**Equal**\n\n```ruby\nfilters = { active_eq: true }\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**NotEqual**\n\n```ruby\nfilters = { active_noteq: true }\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Nested Hash Paths**\n\n```ruby\nfilters = { 'schedule.all_day_eq': false }\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Nested Array Paths**\n\n\u003e Note the `.0` 🎉\n\n```ruby\nfilters = { 'numbers.0_eq': '3' }\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n```ruby\nfilters = { numbers_in: ['1'] }\n\ncollection = Recollect::Array.filter(data, filters)\n\nexpect(collection.size).to eq(1)\n```\n\n**Combine conditions**\n\nYes, you can combine one or multiple predicates to filter you array.\n\n\n```ruby\nfilters = {\n  active_noteq: true,\n  numbers_in: %w[5],\n  email_cont: 'test3',\n  'schedule.all_day_eq': false\n}\n\ncollection = Recollect::Array.filter(data, filters)\n```\n\n**Receive querystring in your route**\n\nLike Ransack, imagine that you receive an querystring and you want to filter your Array. So, you can to do something like this.\n\n\u003e ⚠️ But security is your responsability, ok? Let's go!\n\n```ruby\n# receive querystring in your route\nquerystring = \"active_noteq=true\u0026numbers_in=5\u0026email_cont=test3\u0026schedule.all_day_eq=false\"\n\n# parse querystring and transform to Hash\nparams = URI.decode_www_form(querystring).to_h\n\n# filter your collection using params directly.\ncollection = Recollect::Array.filter(data, filters)\n\n# Beautiful, right? 🎉\n```\n\n[⬆️ \u0026nbsp;Back to Top](#table-of-contents-)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/thadeu/recollect-array. 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/blob/master/CODE_OF_CONDUCT.md).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Frecollect-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthadeu%2Frecollect-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Frecollect-array/lists"}