Module: Jsapi::JSON
- Defined in:
- lib/jsapi/json.rb,
lib/jsapi/json/null.rb,
lib/jsapi/json/array.rb,
lib/jsapi/json/value.rb,
lib/jsapi/json/number.rb,
lib/jsapi/json/object.rb,
lib/jsapi/json/string.rb,
lib/jsapi/json/boolean.rb,
lib/jsapi/json/integer.rb
Overview
Provides a DOM for JSON values.
Defined Under Namespace
Classes: Array, Boolean, Integer, Null, Number, Object, String, Value
Class Method Summary collapse
Class Method Details
.wrap(object, schema, definitions = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jsapi/json.rb', line 16 def wrap(object, schema, definitions = nil) schema = schema.resolve(definitions) unless definitions.nil? object = schema.default if object.nil? return Null.new(schema) if object.nil? case schema.type when 'array' Array.new(object, schema, definitions) when 'boolean' Boolean.new(object, schema) when 'integer' Integer.new(object, schema) when 'number' Number.new(object, schema) when 'object' Object.new(object, schema, definitions) when 'string' String.new(object, schema) else raise "invalid type: #{schema.type}" end end |