Project

jsondoc

0.0
Low commit activity in last 3 years
No release in over a year
A base document object
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13, >= 13.0.6
 Project Readme

JsonDoc

Gem Version Build Status Coverage Status Dependency Status Code Climate Scrutinizer Code Quality Docs License

Generic JSON document base class to set/get document attributes based on JSON Schema, dump as JSON and support building of CSV and Excel workbooks. Subclasses can be built with additional functionality, e.g. using the setAttr method. Primary use cases include being used with parsers to create JSON documents and to create CSV/Excel reports.

Installation

Via Bundler

Add jsondoc to Gemfile and then run bundle:

$ echo "gem 'jsondoc'" >> Gemfile
$ bundle

Via RubyGems

$ gem install jsondoc

Usage

require 'jsondoc'

my_data = {}

my_schema = {
  type: 'My Document Type',
  properties: {
    first_name:      {type: 'string', description: 'First Name', default: ''},
    last_name:       {type: 'string', description: 'Last Name',  default: ''},
    email_addresses: {type: 'array' , description: 'Email Addresses', default: []}
  }
}

thisUser = JsonDoc::Document.new(my_data, my_schema)
thisUser.setAttr(:first_name, 'John')
thisUser.setAttr(:last_name,  'Doe')

first_name = thisUser.getAttr(:first_name)

thisUserHash = thisUser.asHash
thisUserJson = thisUser.asJson

descs  = thisUser.getDescArrayForProperties( [:first_name,:last_name] )
values = thisUser.getValArrayForProperties(  [:first_name,:last_name] )

thisUser.pushAttr(:email_addresses, 'john@example.com')
thisUser.pushAttr(:email_addresses, 'john.doe@example.com')

thisUser.cpAttr(:first_name, :last_name)

Notes

Schema Validation

Schema validation is not provided in this version.

Links

  1. JSON
  1. JSON Schema

License

JsonDoc is available under an MIT-style license. See LICENSE.txt for details.

JsonDoc © 2014-2023 by John Wang