0.01
No release in over 3 years
Low commit activity in last 3 years
DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Ruby Style Guide Actions Status Maintainability Test Coverage Gem Version

DeepOpenStruct

DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.

Installation

Add DeepOpenStruct to your gemfile:

gem 'deepopenstruct', '~>0.1.3'

And then execute:

bundle install

Or install it manually by entering the following at your command line:

gem install deepopenstruct

Usage

require 'rubygems'
require 'deepopenstruct'

complex_data = {
  :name => "Bob Winkle",
  :age => 65,
  :jobs => [
    {'start_year' => 1980, 'title' => 'Chef'},
    {'start_year' => 1985, 'title' => 'Programmer'}
  ],
  :attributes => {
    :birthplace => "Darwin",
    :year_of_birth => 1945
  }
}

simple_data = DeepOpenStruct.load(complex_data)

simple_data.name
# => "Bob Winkle"

simple_data.jobs.first.title
# => "Chef"

simple_data.attributes.birthplace
# => "Darwin"

Contributing:

Contributions are always welcome! Please create a pull request that clearly outlines the work you've done. Make sure your changes include updating or adding relevant tests, and use Rubocop to make sure your additions adhere to the same style as the rest of the project!

Author & Credits:

Author: Aaron Gough Copyright © 2022 Aaron Gough, released under the MIT license