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.
56 57 58 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 56 def initialize(string) parse(string) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
54 55 56 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 54 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.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 74 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 = Parsers::Type.run(data_type) @required = required @options = end |
#required? ⇒ Boolean
60 61 62 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 60 def required? @required end |
#to_doc ⇒ Object
64 65 66 67 68 69 |
# File 'lib/swaggard/swagger/parameters/body.rb', line 64 def to_doc result = @type.to_doc result['description'] = @description if @description result['enum'] = @options if @options.present? result end |