https://github.com/acook/enumerable_deep_search
Recursively search enumerable objects
https://github.com/acook/enumerable_deep_search
data-exploration data-mining nested-objects
Last synced: 6 months ago
JSON representation
Recursively search enumerable objects
- Host: GitHub
- URL: https://github.com/acook/enumerable_deep_search
- Owner: acook
- License: mit
- Created: 2012-08-21T18:35:24.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-09-22T17:56:09.000Z (over 9 years ago)
- Last Synced: 2025-06-03T03:14:15.978Z (7 months ago)
- Topics: data-exploration, data-mining, nested-objects
- Language: Ruby
- Homepage: https://github.com/acook/enumerable_deep_search#readme
- Size: 19.5 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE.txt
Awesome Lists containing this project
README
# EnumerableDeepSearch
Recursively searches enumerable objects and their nested objects for a given object or string.
[](https://travis-ci.org/acook/enumerable_deep_search)
[](https://codeclimate.com/github/acook/enumerable_deep_search)
## Installation
Add this line to your application's Gemfile:
gem 'enumerable_deep_search'
And then execute:
$ bundle
Or install it yourself as:
$ gem install enumerable_deep_search
## Usage
In practice it's an exploration tool, I recommend using it with [Pry](http://pryrepl.org) and extending objects as needed.
You can also include it on a class and all the instances will inherit the functionality.
Personally I've found this the most useful for searching web apis converted from XML and JSON into Ruby objects.
Its useful on any large nested data, such as configuration structures dumped from YAML files.
example:
```ruby
object.extend EnumerableDeepSearch
object.search 'something'
```
It will return a facimile of the path to the matching object, for hash-like objects it will return a Hash containing the match as well as the opposite pair (either the key or the value), for array-like objects it will return a two element Array where the first element is the index of the match and second element the match itself.
example:
```ruby
object.search 'something'
#=> {:foo => [1, 'something']}
```
## Ideas? Complaints?
- You could Contribute: https://github.com/acook/enumerable_deep_search/fork
- Or you could Submit an issue: https://github.com/acook/enumerable_deep_search/issues
- Or you could even ping me on Twitter: http://twitter.com/anthony_m_cook
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request