Sha256: f9c728332478ea40940d99ad67a5b62ff1d36c6d6d4d201fe27c65830acbff89

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'multi_json'
module Fitting
  class Route
    class Coverage
      def initialize(coverage_responses, responses_routes, strict)
        @coverage_responses = coverage_responses
        @responses_routes = responses_routes
        @strict = strict
      end

      def coverage
        @coverage ||= @responses_routes - (@responses_routes - full_coverage)
      end

      def not_coverage
        @not_coverage ||= @responses_routes - coverage
      end

      def cover_ratio
        @cover_ratio ||= (coverage.size.to_f / @responses_routes.size.to_f * 100.0).round(2)
      end

      def to_hash
        {
          'coverage' => coverage,
          'not coverage' => not_coverage
        }
      end

      private

      def full_coverage
        if @strict
          @coverage_responses.map do |response|
            response.strict_route if response.documented? && response.strict_fully_validates.valid?
          end.flatten.compact.uniq
        else
          @coverage_responses.map do |response|
            response.route if response.documented? && response.fully_validates.valid?
          end.flatten.compact.uniq
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fitting-2.2.0 lib/fitting/route/coverage.rb
fitting-2.1.3 lib/fitting/route/coverage.rb
fitting-2.1.2 lib/fitting/route/coverage.rb