Class: Swaggard::Swagger::Parameters::Body::Property
- Inherits:
-
Object
- Object
- Swaggard::Swagger::Parameters::Body::Property
- Defined in:
- lib/swaggard/swagger/parameters/body.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(string) ⇒ Property
constructor
A new instance of Property.
-
#parse(string) ⇒ Object
Example: [Array] status Filter by status.
- #required? ⇒ Boolean
- #to_doc ⇒ Object
Constructor Details
#initialize(string) ⇒ Property
Returns a new instance of Property.
59 60 61 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 59 def initialize(string) parse(string) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
57 58 59 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 57 def id @id end |
Instance Method Details
#parse(string) ⇒ Object
Example: [Array] status Filter by status. (e.g. status[]=1&status=2&status[]=3) Example: [Array] status(required) Filter by status. (e.g. status[]=1&status=2&status[]=3) Example: [Integer] media ID of the desired media type.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 77 def parse(string) string.gsub!("\n", ' ') data_type, required, name, = string.match(/\A\[(\S*)\](!)?\s*([\w\[\]]*)\s*(.*)\Z/).captures allow_multiple = name.gsub!('[]', '') , description = .match(/\A(\[.*\])?(.*)\Z/).captures = ? .gsub(/\[?\]?\s?/, '').split(',') : [] @id = name @description = description if description.present? @type = Type.new([data_type]) @required = required @options = end |
#required? ⇒ Boolean
63 64 65 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 63 def required? @required end |
#to_doc ⇒ Object
67 68 69 70 71 72 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 67 def to_doc result = @type.to_doc result['description'] = @description if @description result['enum'] = @options if @options.present? result end |