Socket
Book a DemoInstallSign in
Socket

sparsify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparsify

1.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

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'}}})
#=> {'foo.bar.baz' => 'bingo'}

Unsparsify({'foo.bar.baz' => 'bingo'})
#=> {'foo' => { 'bar' => {'baz' => 'bingo'}}}

Advanced Usage

Custom Separator

require 'sparsify'

Sparsify({'foo' => { 'bar.bar' => {'baz' => 'bingo'}}}, separator: '|')
#=> {'foo|bar.bar|baz' => 'bingo'}

Unsparsify({'foo|bar.bar|baz' => 'bingo'}, separator: '|')
#=> {'foo' => { 'bar.bar' => {'baz' => 'bingo'}}}

Sparse Arrays

require 'sparsify'

Sparsify({'foo' => ['bar','baz','buz']}, sparse_array: true)
#=> {'foo.0'=>'bar','foo.1'=>'baz','foo.2'=>'buz'}

Unsparsify({'foo.0'=>'bar','foo.1'=>'baz','foo.2'=>'buz'}, sparse_array: true)
#=> {'foo' => ['bar','baz','buz']}

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

FAQs

Package last updated on 04 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.