Sparsify
Convert a deeply-nested hash into a shallow sparse hash. Useful for tools that
either can't handle deeply-nested hashes or that allow partial updates via
sparse hashes.
This gem is our internal implementation of our [Sparisfy Challenge][].
Usage
require 'sparsify'
Sparsify({'foo' => { 'bar' => {'baz' => 'bingo'}}})
Unsparsify({'foo.bar.baz' => 'bingo'})
Advanced Usage
Custom Separator
require 'sparsify'
Sparsify({'foo' => { 'bar.bar' => {'baz' => 'bingo'}}}, separator: '|')
Unsparsify({'foo|bar.bar|baz' => 'bingo'}, separator: '|')
Sparse Arrays
require 'sparsify'
Sparsify({'foo' => ['bar','baz','buz']}, sparse_array: true)
Unsparsify({'foo.0'=>'bar','foo.1'=>'baz','foo.2'=>'buz'}, sparse_array: true)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create new Pull Request