Class: Schai::Property

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) ⇒ Property

Returns a new instance of Property.



140
141
142
143
144
145
# File 'lib/schai/hoge.rb', line 140

def initialize params
  params.each do |k, v|
    setter = "#{k}=".to_sym
    self.send(setter, v)
  end
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



130
131
132
# File 'lib/schai/hoge.rb', line 130

def format
  @format
end

#typeObject

Returns the value of attribute type.



130
131
132
# File 'lib/schai/hoge.rb', line 130

def type
  @type
end

Class Method Details

.parse(params) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/schai/hoge.rb', line 132

def self.parse params
  if params.has_key? 'include'
    Schai.parse_file(params['include']).schema
  else
    self.new params
  end
end

Instance Method Details

#to_schemaObject



147
148
149
150
151
152
153
154
# File 'lib/schai/hoge.rb', line 147

def to_schema
  ret = {}
  ret[:type] = (@type || 'null').to_sym
  ret[:format] = @format if @format
  ret[:description] = @description if @description
  ret[:example] = @example if @example
  ret
end