Sha256: fa673188b546744c499987fd95f817b7dae2845918a9cc505985c751d20edd62

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Fitting
  class Statistics
    class List
      def initialize(coverage, max_response_path)
        @coverage = coverage
        @max_response_path = max_response_path
      end

      def to_s
        list_sort.inject([]) do |res, request|
          res.push("#{request.method}\t#{request.path}#{responses_stat(request)}")
        end.join("\n")
      end

      def list_sort
        @coverage.sort do |first, second|
          first.path.to_s <=> second.path.to_s
        end
      end

      def responses_stat(request)
        tab = "\t" * ((@max_response_path - request.path.to_s.size / 8) + 3)
        tab + request.responses.to_a.each_with_object([]) do |response, res|
          response_stat(response, res)
        end.join(' ')
      end

      private

      def response_stat(response, res)
        response.json_schemas.map do |json_schema|
          json_schema_stat(res, json_schema, response)
        end
      end

      def json_schema_stat(res, json_schema, response)
        if json_schema.bodies == []
          res.push("✖ #{response.status}")
        else
          res.push("✔ #{response.status}")
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fitting-2.6.0 lib/fitting/statistics/list.rb
fitting-2.5.0 lib/fitting/statistics/list.rb
fitting-2.4.1 lib/fitting/statistics/list.rb
fitting-2.4.0 lib/fitting/statistics/list.rb
fitting-2.3.0 lib/fitting/statistics/list.rb