Class: Schai::JsProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/schai/json_schema/js_property.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ JsProperty

Returns a new instance of JsProperty.



13
14
15
16
17
18
# File 'lib/schai/json_schema/js_property.rb', line 13

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

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/schai/json_schema/js_property.rb', line 3

def description
  @description
end

#exampleObject

Returns the value of attribute example.



3
4
5
# File 'lib/schai/json_schema/js_property.rb', line 3

def example
  @example
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/schai/json_schema/js_property.rb', line 3

def format
  @format
end

#optionalObject

Returns the value of attribute optional.



3
4
5
# File 'lib/schai/json_schema/js_property.rb', line 3

def optional
  @optional
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/schai/json_schema/js_property.rb', line 3

def type
  @type
end

Class Method Details

.parse(params) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/schai/json_schema/js_property.rb', line 5

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



20
21
22
23
24
25
26
27
# File 'lib/schai/json_schema/js_property.rb', line 20

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