Class: JsonSchema::Parser
- Inherits:
-
Object
- Object
- JsonSchema::Parser
- Defined in:
- lib/json_schema/parser.rb
Constant Summary collapse
- ALLOWED_TYPES =
%w{any array boolean integer number null object string}
- BOOLEAN =
[FalseClass, TrueClass]
- FORMATS =
%w{date date-time email hostname ipv4 ipv6 regex uri uuid}
- FRIENDLY_TYPES =
{ Array => "array", FalseClass => "boolean", Float => "number", Hash => "object", Integer => "integer", NilClass => "null", String => "string", TrueClass => "boolean", }
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
-
#parse(data, parent = nil) ⇒ Object
Basic parsing of a schema.
- #parse!(data, parent = nil) ⇒ Object
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
19 20 21 |
# File 'lib/json_schema/parser.rb', line 19 def errors @errors end |
Instance Method Details
#parse(data, parent = nil) ⇒ Object
Basic parsing of a schema. May return a malformed schema! (Use ‘#parse!` to raise errors instead).
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/json_schema/parser.rb', line 23 def parse(data, parent = nil) # while #parse_data is recursed into for many schemas over the same # object, the @errors array is an instance-wide accumulator @errors = [] schema = parse_data(data, parent, "#") if @errors.count == 0 schema else nil end end |
#parse!(data, parent = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/json_schema/parser.rb', line 36 def parse!(data, parent = nil) schema = parse(data, parent) if !schema raise @errors.join(" ") end schema end |