Class: Schai::Object

Inherits:
Object
  • Object
show all
Includes:
Metadata, Optional
Defined in:
lib/schai/hoge.rb

Instance Attribute Summary collapse

Attributes included from Metadata

#description, #example

Attributes included from Optional

#optional

Class Method Summary collapse

Instance Method Summary collapse

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

#allObject

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_schemaObject



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