Sha256: 122f1bd21a18208a3e37b9722210a5bf7c14f109f477c09180dd98cef2b2bab8

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'simplecov_json_formatter/source_file_formatter'

module SimpleCovJSONFormatter
  class ResultHashFormatter
    def initialize(result)
      @result = result
    end

    def format
      format_files
      format_groups

      formatted_result
    end

    private

    def format_files
      @result.files.each do |source_file|
        formatted_result[:coverage][source_file.filename] =
          format_source_file(source_file)
      end
    end

    def format_groups
      @result.groups.each do |name, file_list|
        formatted_result[:groups][name] = {
          lines: {
            covered_percent: file_list.covered_percent
          }
        }
      end
    end

    def formatted_result
      @formatted_result ||= {
        meta: {
          simplecov_version: SimpleCov::VERSION
        },
        coverage: {},
        groups: {}
      }
    end

    def format_source_file(source_file)
      source_file_formatter = SourceFileFormatter.new(source_file)
      source_file_formatter.format
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/simplecov_json_formatter-0.1.4/lib/simplecov_json_formatter/result_hash_formatter.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/simplecov_json_formatter-0.1.4/lib/simplecov_json_formatter/result_hash_formatter.rb
simplecov_json_formatter-0.1.4 lib/simplecov_json_formatter/result_hash_formatter.rb