Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Converts ruby hashes and arrays into objects. Also works with JSON & YAML files.

License

Notifications You must be signed in to change notification settings

thunderboltlabs/deep_struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deep Struct

A library to access nested hashes and arrays in an object oriented way.

Requires Ruby 1.9.3 or higher

Examples

data = [
  { one: 1, two: 2 },
  { "array": [ "string", "another"] },
  { "nested": [ { "name" => "Sue" } ] },
]

deep_struct = DeepStruct.from_data(data)

deep_struct[0].one               # => 1
deep_struct[0].two               # => 2
deep_struct[1].array             # => ["string", "another"]
deep_struct[2].nested.first.name # => "Sue"

Note that DeepStruct does its best to return nested DeepStruct objects, even when accessed through contained arrays. It accomplishes this by returning DeepStruct::Array or DeepStruct::Hash objects.

Reading from files

DeepStruct can also load data files from the filesystem:

DeepStruct.from_file("./data.json")
DeepStruct.from_file("./data.yaml")

Installing

# Gemfile
gem "deep_struct"

Bugs and Issues

Please submit them via github issues.

Suggestions

If you have any suggestions on how to improve DeepStruct please suggest them through the issues system.

Development

In order to work on DeepStruct you first need to fork and clone the repo. Please do any work on a dedicated branch and rebase against master before sending a pull request.

No submissions will be accepted without specs.

Copyright

Copyright (c) 2009-2012 Thunderbolt Labs. See LICENSE for details.

About

Converts ruby hashes and arrays into objects. Also works with JSON & YAML files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages