Sha256: dff7d8285385e414564a754184c9f738b47e2f97e23c78766891de4c57bb1fe9

Contents?: true

Size: 854 Bytes

Versions: 3

Compression:

Stored size: 854 Bytes

Contents

autoload :YAML, 'yaml'
autoload :JSON, 'json'

module Swagger
  # Provides classes for loading Swagger from YAML or JSON.
  module Parsers
    def self.parser_for(format)
      case format
      when '.yaml', '.yml', :yaml
        YAMLParser
      when '.json', '.js', :json
        JSONParser
      else
        nil
      end
    end

    # Parses YAML content
    class YAMLParser
      # Parses a YAML document
      # @param content [String] The YAML content to parse
      # @return [Hash] the parsed content
      def self.parse(content)
        YAML.load(content)
      end
    end

    # Parses JSON content
    class JSONParser
      # Parses a JSON document
      # @param content [String] The JSON content to parse
      # @return [Hash] the parsed content
      def self.parse(content)
        JSON.parse(content)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
swagger-core-0.2.3 lib/swagger/parsers.rb
swagger-core-0.2.2 lib/swagger/parsers.rb
swagger-core-0.2.1 lib/swagger/parsers.rb