README.md in jsi-0.2.0 vs README.md in jsi-0.2.1

- old
+ new

@@ -1,6 +1,6 @@ -# JSI: JSON-Schema Instantiation +# JSI: JSON Schema Instantiation [![Build Status](https://travis-ci.org/notEthan/jsi.svg?branch=master)](https://travis-ci.org/notEthan/jsi) [![Coverage Status](https://coveralls.io/repos/github/notEthan/jsi/badge.svg)](https://coveralls.io/github/notEthan/jsi) JSI offers an Object-Oriented representation for JSON data using JSON Schemas. Given your JSON Schemas, JSI constructs Ruby classes which are used to instantiate your JSON data. These classes let you use JSON with all the niceties of OOP such as property accessors and application-defined instance methods. @@ -25,22 +25,31 @@ properties: location: {type: "string"} number: {type: "string"} ``` -And here's the class for that schema from JSI: +And here's how you'd normally instantiate the class for that schema using JSI: ```ruby -Contact = JSI.class_for_schema(YAML.load_file('contact.schema.yml')) -# you can copy/paste this line instead, to follow along in irb: +# this would usually use a YAML.load/JSON.parse/whatever; it's inlined for copypastability. Contact = JSI.class_for_schema({"description" => "A Contact", "type" => "object", "properties" => {"name" => {"type" => "string"}, "phone" => {"type" => "array", "items" => {"type" => "object", "properties" => {"location" => {"type" => "string"}, "number" => {"type" => "string"}}}}}}) ``` -This definition gives you not just the Contact class, but classes for the whole nested structure. So, if we construct an instance like: +This definition gives you not just the Contact class, but classes for the whole nested structure. To instantiate it, we need some JSON data (expressed here as YAML) -```ruby -bill = Contact.new('name' => 'bill', 'phone' => [{'location' => 'home', 'number' => '555'}], 'nickname' => 'big b') +```yaml +name: bill +phone: +- location: home + number: "555" +nickname: big b +``` +So, if we construct an instance like: + +```ruby +# this would usually use a YAML.load/JSON.parse/whatever; it's inlined for copypastability. +bill = Contact.new({"name" => "bill", "phone" => [{"location" => "home", "number" => "555"}], "nickname" => "big b"}) # => #{<Contact Hash> # "name" => "bill", # "phone" => #[<JSI::SchemaClasses["23d8#/properties/phone"] Array> # #{<JSI::SchemaClasses["23d8#/properties/phone/items"] Hash> "location" => "home", "number" => "555"} # ],