Class: Schai::Object
- Inherits:
-
Object
- Object
- Schai::Object
- Defined in:
- lib/schai/hoge.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
Attributes included from Metadata
Attributes included from Optional
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Object
constructor
A new instance of Object.
- #to_schema ⇒ Object
Constructor Details
#initialize(params) ⇒ Object
Returns a new instance of Object.
79 80 81 82 83 84 85 86 |
# File 'lib/schai/hoge.rb', line 79 def initialize params @all = Hash[params["properties"].map {|k, v| [k || 'null', Root.parse_components(v)] }] @description = params["description"] @example = params["example"] @optional = params["optional"] end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
73 74 75 |
# File 'lib/schai/hoge.rb', line 73 def all @all end |
Class Method Details
.parse(params) ⇒ Object
75 76 77 |
# File 'lib/schai/hoge.rb', line 75 def self.parse params self.new params end |
Instance Method Details
#to_schema ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/schai/hoge.rb', line 88 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 |