Sha256: 77206645b1ed6c7585e0549873d6e9c9216c97fceb7b70c25c9d1ddb404e899d

Contents?: true

Size: 1.04 KB

Versions: 19

Compression:

Stored size: 1.04 KB

Contents

require 'fitting/cover/json_schema'
require 'json-schema'

module Fitting
  class Cover
    class Response
      def initialize(response)
        @cover_json_schemas = Fitting::Cover::JSONSchema.new(response.json_schema)
        @json_schemas = @cover_json_schemas.json_schemas + [response.json_schema]
        @combinations = @cover_json_schemas.combinations
        @flags = @cover_json_schemas.json_schemas.map do |json_schema|
          JSON::Validator.validate(json_schema, response.body)
        end
      end

      attr_reader :json_schemas

      attr_reader :combinations

      attr_reader :flags

      def update(response)
        index = 0
        @cover_json_schemas.json_schemas.map do |json_schema|
          flag = JSON::Validator.validate(json_schema, response.body)
          @flags[index] = @flags[index] || flag
          index += 1
        end
        self
      end

      def to_hash
        {
          'json_schemas' => json_schemas,
          'combinations' => combinations,
          'flags' => flags
        }
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
fitting-2.17.0 lib/fitting/cover/response.rb
fitting-2.16.1 lib/fitting/cover/response.rb
fitting-2.16.0 lib/fitting/cover/response.rb
fitting-2.15.0 lib/fitting/cover/response.rb
fitting-2.14.1 lib/fitting/cover/response.rb
fitting-2.14.0 lib/fitting/cover/response.rb
fitting-2.13.1 lib/fitting/cover/response.rb
fitting-2.13.0 lib/fitting/cover/response.rb
fitting-2.12.1 lib/fitting/cover/response.rb
fitting-2.12.0 lib/fitting/cover/response.rb
fitting-2.11.0 lib/fitting/cover/response.rb
fitting-2.10.0 lib/fitting/cover/response.rb
fitting-2.9.1 lib/fitting/cover/response.rb
fitting-2.9.0 lib/fitting/cover/response.rb
fitting-2.8.1 lib/fitting/cover/response.rb
fitting-2.8.0 lib/fitting/cover/response.rb
fitting-2.7.2 lib/fitting/cover/response.rb
fitting-2.7.1 lib/fitting/cover/response.rb
fitting-2.7.0 lib/fitting/cover/response.rb