Sha256: 6f2692d0dd9e83d80abd70a2715d49dc8cb0815bec83792cf7f3424ad3cb207a

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

module Swaggard
  module Swagger
    class ResponseHeader
      attr_reader :name

      def initialize(string)
        parse(string)
      end

      def to_doc
        {
          'description' => @description,
          'type'        => @type,
        }
      end

      private

      # Example: [Array]     status            Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
      # Example: [Array]!    status  Filter by status. (e.g. status[]=1&status[]=2&status[]=3)
      # Example: [Integer]   media[media_type_id]                          ID of the desired media type.
      def parse(string)
        data_type, name, options_and_description = string.match(/\A\[(\S*)\]\s*([\w\-\[\]]*)\s*(.*)\Z/).captures
        allow_multiple = name.gsub!('[]', '')

        options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
        options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []

        @name = name
        @description = description
        @type = data_type
        @allow_multiple = allow_multiple.present?
        @options = options
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
swaggard-1.5.1 lib/swaggard/swagger/response_header.rb
swaggard-1.5.0 lib/swaggard/swagger/response_header.rb
swaggard-1.4.0 lib/swaggard/swagger/response_header.rb
swaggard-1.3.0 lib/swaggard/swagger/response_header.rb
swaggard-1.2.0 lib/swaggard/swagger/response_header.rb
swaggard-1.1.1 lib/swaggard/swagger/response_header.rb
swaggard-1.1.0 lib/swaggard/swagger/response_header.rb
swaggard-1.0.2 lib/swaggard/swagger/response_header.rb
swaggard-1.0.1 lib/swaggard/swagger/response_header.rb
swaggard-1.0.0 lib/swaggard/swagger/response_header.rb