Sha256: df033b7edefc7252602fcd8a9aa3d7357dc172257ab1f0bbd7def32b2b70c5d9

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 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
      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

2 entries across 2 versions & 1 rubygems

Version Path
swagger-parser-0.2.6 lib/swagger/parsers.rb
swagger-parser-0.2.5 lib/swagger/parsers.rb