Class: SchemaTest::Property
- Inherits:
-
Object
- Object
- SchemaTest::Property
show all
- Defined in:
- lib/schema_test/property.rb
Defined Under Namespace
Classes: AnonymousObject, Array, Boolean, DateTime, Float, Integer, Object, String, UnresolvedProperty, Uri
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, type, description = nil) ⇒ Property
Returns a new instance of Property.
5
6
7
8
9
10
|
# File 'lib/schema_test/property.rb', line 5
def initialize(name, type, description=nil)
@name = name
@type = type
@description = description
@optional = false
end
|
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3
4
5
|
# File 'lib/schema_test/property.rb', line 3
def description
@description
end
|
Returns the value of attribute name.
3
4
5
|
# File 'lib/schema_test/property.rb', line 3
def name
@name
end
|
Returns the value of attribute optional.
3
4
5
|
# File 'lib/schema_test/property.rb', line 3
def optional
@optional
end
|
Returns the value of attribute type.
3
4
5
|
# File 'lib/schema_test/property.rb', line 3
def type
@type
end
|
Instance Method Details
#==(other) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/schema_test/property.rb', line 27
def ==(other)
name == other.name &&
type == other.type &&
description == other.description &&
optional == other.optional
end
|
#as_json_schema ⇒ Object
20
21
22
23
24
25
|
# File 'lib/schema_test/property.rb', line 20
def as_json_schema
json_schema = { 'type' => json_schema_type }
json_schema['description'] = description if description
json_schema['format'] = json_schema_format if json_schema_format
{ name.to_s => json_schema }
end
|
#as_structure(_ = nil) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/schema_test/property.rb', line 12
def as_structure(_=nil)
if @optional
{ name => nil }
else
name
end
end
|
46
47
48
|
# File 'lib/schema_test/property.rb', line 46
def json_schema_format
nil
end
|
#json_schema_type ⇒ Object
42
43
44
|
# File 'lib/schema_test/property.rb', line 42
def json_schema_type
@type.to_s
end
|
#optional! ⇒ Object
38
39
40
|
# File 'lib/schema_test/property.rb', line 38
def optional!
@optional = true
end
|
34
35
36
|
# File 'lib/schema_test/property.rb', line 34
def optional?
optional
end
|