Class: SimpleCov::Formatter::JSONFormatter::SourceFileFormatter
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/simplecov/formatter/json_formatter/source_file_formatter.rb |
Class Method Summary
- .new(source_file) ⇒ SourceFileFormatter constructor
Instance Method Summary
- #format
- #branch_coverage private
- #branches private
- #format_methods private
- #line_coverage private
- #lines private
- #method_coverage private
- #parse_branch(branch) private
- #parse_line(line) private
- #parse_method(method) private
Constructor Details
.new(source_file) ⇒ SourceFileFormatter
# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 7
def initialize(source_file) @source_file = source_file @line_coverage = nil end
Instance Method Details
#branch_coverage (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 28
def branch_coverage { branches: branches, branches_covered_percent: @source_file.branches_coverage_percent } end
#branches (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 48
def branches @source_file.branches.collect do |branch| parse_branch(branch) end end
#format
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 12
def format result = line_coverage result.merge!(branch_coverage) if SimpleCov.branch_coverage? result.merge!(method_coverage) if SimpleCov.method_coverage? result end
#format_methods (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 54
def format_methods @source_file.methods.collect do |method| parse_method(method) end end
#line_coverage (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 21
def line_coverage @line_coverage ||= { lines: lines, lines_covered_percent: @source_file.covered_percent } end
#lines (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 42
def lines @source_file.lines.collect do |line| parse_line(line) end end
#method_coverage (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 35
def method_coverage { methods: format_methods, methods_covered_percent: @source_file.methods_coverage_percent } end
#parse_branch(branch) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 66
def parse_branch(branch) { type: branch.type, start_line: branch.start_line, end_line: branch.end_line, coverage: parse_line(branch) } end
#parse_line(line) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 60
def parse_line(line) return line.coverage unless line.skipped? "ignored" end
#parse_method(method) (private)
[ GitHub ]# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 75
def parse_method(method) { name: method.to_s, start_line: method.start_line, end_line: method.end_line, coverage: parse_line(method) } end