Class: Jdoc::Property
- Inherits:
-
Object
- Object
- Jdoc::Property
- Defined in:
- lib/jdoc/property.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#description ⇒ String?
Description text, defined in description property.
-
#example ⇒ String?
Example value, defined in example property.
-
#format ⇒ Stirng?
Format constraint, defined in format property.
-
#initialize(name: nil, schema: nil) ⇒ Property
constructor
A new instance of Property.
-
#options ⇒ Hash
Key-Value pair of metadata of this property.
-
#pattern ⇒ String?
Pattern constraint, defined in pattern property.
-
#read_only ⇒ true?
True if readOnly property is defined and it’s true.
-
#type ⇒ String?
Possible types defined in type property.
Constructor Details
#initialize(name: nil, schema: nil) ⇒ Property
Returns a new instance of Property.
7 8 9 10 |
# File 'lib/jdoc/property.rb', line 7 def initialize(name: nil, schema: nil) @name = name @schema = schema end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/jdoc/property.rb', line 3 def name @name end |
Instance Method Details
#description ⇒ String?
Returns Description text, defined in description property.
24 25 26 |
# File 'lib/jdoc/property.rb', line 24 def description @schema.description end |
#example ⇒ String?
Returns Example value, defined in example property.
29 30 31 32 33 |
# File 'lib/jdoc/property.rb', line 29 def example if @schema.data.has_key?("example") %<`#{@schema.data["example"].inspect}`> end end |
#format ⇒ Stirng?
Returns Format constraint, defined in format property.
43 44 45 |
# File 'lib/jdoc/property.rb', line 43 def format @schema.format end |
#options ⇒ Hash
Returns Key-Value pair of metadata of this property.
13 14 15 16 17 18 19 20 21 |
# File 'lib/jdoc/property.rb', line 13 def { Example: example, Type: type, Format: format, Pattern: pattern, ReadOnly: read_only, }.reject {|key, value| value.nil? } end |
#pattern ⇒ String?
Returns Pattern constraint, defined in pattern property.
36 37 38 39 40 |
# File 'lib/jdoc/property.rb', line 36 def pattern if str = @schema.pattern "`#{str.inspect}`" end end |
#read_only ⇒ true?
Returns True if readOnly property is defined and it’s true.
48 49 50 |
# File 'lib/jdoc/property.rb', line 48 def read_only true if @schema.read_only == true end |
#type ⇒ String?
Returns Possible types defined in type property.
53 54 55 56 57 |
# File 'lib/jdoc/property.rb', line 53 def type unless @schema.type.empty? @schema.type.join(", ") end end |