Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Create a hash with hash an array elements from a key,value hash.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
Changelog
Gemfile
README.md
Rakefile
nested_hash.gemspec

README.md

NestedHash

NestedHash is a Hash converter. It will created a simple, key encoded hash, in to a nested hash. For example, the hash:

{
  "name" => "guillermo",
  "properties.age" => 29,
  "properties.sex" => "male",
  "parents.1" => "ramon",
  "parents.2" => "gloria"
}

will be converted into the hash

{
  "name" => "guillermo",
  "properties" => {
    "age" => 29,
    "sex" => "male"
  },
  "parents" => [ "ramon", "gloria" ]
}

Usage

require 'nested_hash'

my_normal_hash = {
  "name" => "guillermo",
  "properties.age" => 29,
  "properties.sex" => "male",
  "parents.1" => "ramon",
  "parents.2" => "gloria"
}

my_new_hash = NestedHash.new(my_normal_hash)
my_new_hash # => {"name"=>"guillermo", "properties"=>{"age"=>29, "sex"=>"male"}, "parents"=>["ramon", "gloria"]}

NestedHash inherits from Hash, so you can use it as a normal hash.

Installation

$ gem install nested_hash

Motivations

The reason for creating this ruby gem is to convert Excel files to json files. With the rubygems roo you already can get the rows into a one level hash (colum title as a key). This complement help to create more difficult structures with the same excel file.

License

Mit

Something went wrong with that request. Please try again.