Sha256: 7343d1d342dd0f0a6bd017d3a0a986539a746b8551a98b063a443bb6da209bb9

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Fitting
  module Report
    class Combinations
      def initialize(combinations)
        @combinations = combinations
      end

      def to_a
        @combinations
      end

      def size
        @combinations.size
      end

      def size_with_tests
        @combinations.count { |c| c.tests.size != 0 }
      end

      def join(tests)
        tests.to_a.map do |test|
          if is_there_a_suitable_combination?(test)
            cram_into_the_appropriate_combinations(test)
            test.mark_combination
          end
        end
      end

      def is_there_a_suitable_combination?(test)
        return false if @combinations.nil?
        @combinations.map do |combination|
          return true if JSON::Validator.fully_validate(combination.json_schema, test.body) == []
        end

        false
      end

      def cram_into_the_appropriate_combinations(test)
        @combinations.map do |combination|
          if JSON::Validator.fully_validate(combination.json_schema, test.body) == []
            combination.add_test(test)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fitting-2.17.0 lib/fitting/report/combinations.rb
fitting-2.16.1 lib/fitting/report/combinations.rb
fitting-2.16.0 lib/fitting/report/combinations.rb
fitting-2.15.0 lib/fitting/report/combinations.rb
fitting-2.14.1 lib/fitting/report/combinations.rb
fitting-2.14.0 lib/fitting/report/combinations.rb