Class: Swaggard::Swagger::Property
- Inherits:
-
Object
- Object
- Swaggard::Swagger::Property
- Defined in:
- lib/swaggard/swagger/property.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(yard_object) ⇒ Property
constructor
A new instance of Property.
- #required? ⇒ Boolean
- #to_doc ⇒ Object
Constructor Details
#initialize(yard_object) ⇒ Property
Returns a new instance of Property.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/swaggard/swagger/property.rb', line 9 def initialize(yard_object) name = yard_object.name.dup = yard_object.text&.dup || '' .gsub!("\n", ' ') , description = .match(/\A(\[.*\])?(.*)\Z/).captures = ? .gsub(/\[?\]?\s?/, '').split(',') : [] description = description.strip required = name.gsub!(/^!/, '') @id = name @type = Type.new(yard_object.types) @description = description @required = required.present? @options = end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/swaggard/swagger/property.rb', line 7 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/swaggard/swagger/property.rb', line 7 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/swaggard/swagger/property.rb', line 7 def type @type end |
Instance Method Details
#required? ⇒ Boolean
26 27 28 |
# File 'lib/swaggard/swagger/property.rb', line 26 def required? @required end |
#to_doc ⇒ Object
30 31 32 33 34 35 |
# File 'lib/swaggard/swagger/property.rb', line 30 def to_doc result = @type.to_doc result['description'] = @description if @description.present? result['enum'] = @options if @options.present? result end |