Sha256: 4f3d16c87e1fafb77aa97ba399cfd47f8e28d1ac75d23892f7980724c7a02869

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 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.compact.uniq
        else
          @coverage_responses.map do |response|
            response.route if response.documented? && response.fully_validates.valid?
          end.compact.uniq
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fitting-2.1.1 lib/fitting/route/coverage.rb
fitting-2.1.0 lib/fitting/route/coverage.rb
fitting-2.0.3 lib/fitting/route/coverage.rb
fitting-2.0.2 lib/fitting/route/coverage.rb
fitting-2.0.1 lib/fitting/route/coverage.rb
fitting-2.0.0 lib/fitting/route/coverage.rb
fitting-1.6.2 lib/fitting/route/coverage.rb
fitting-1.6.1 lib/fitting/route/coverage.rb
fitting-1.6.0 lib/fitting/route/coverage.rb