Class: Schai::JsObject
- Inherits:
-
Object
- Object
- Schai::JsObject
- Defined in:
- lib/schai/json_schema/js_object.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#description ⇒ Object
Returns the value of attribute description.
-
#example ⇒ Object
Returns the value of attribute example.
-
#optional ⇒ Object
Returns the value of attribute optional.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ JsObject
constructor
A new instance of JsObject.
- #to_schema ⇒ Object
Constructor Details
#initialize(params) ⇒ JsObject
Returns a new instance of JsObject.
9 10 11 12 13 14 15 16 |
# File 'lib/schai/json_schema/js_object.rb', line 9 def initialize params @all = Hash[params["properties"].map {|k, v| [k || 'null', JsRoot.parse_components(v)] }.select{|p| !p[1].nil? }] @description = params["description"] @example = params["example"] @optional = params["optional"] end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
3 4 5 |
# File 'lib/schai/json_schema/js_object.rb', line 3 def all @all end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/schai/json_schema/js_object.rb', line 3 def description @description end |
#example ⇒ Object
Returns the value of attribute example.
3 4 5 |
# File 'lib/schai/json_schema/js_object.rb', line 3 def example @example end |
#optional ⇒ Object
Returns the value of attribute optional.
3 4 5 |
# File 'lib/schai/json_schema/js_object.rb', line 3 def optional @optional end |
Class Method Details
.parse(params) ⇒ Object
5 6 7 |
# File 'lib/schai/json_schema/js_object.rb', line 5 def self.parse params self.new params end |
Instance Method Details
#to_schema ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/schai/json_schema/js_object.rb', line 18 def to_schema schema = {} schema[:type] = :object schema[:description] = @description if @description schema[:properties] = Hash[@all.map {|k, p| [k, p.to_schema]}] schema[:required] = @all.select{|k, p| !p.optional}.map{|k, p| k || 'null'} schema[:example] = @example if @example schema end |