Class: Undercover::LcovParser
- Inherits:
-
Object
- Object
- Undercover::LcovParser
- Includes:
- RootToRelativePaths
- Defined in:
- lib/undercover/lcov_parser.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#source_files ⇒ Object
readonly
Returns the value of attribute source_files.
Class Method Summary collapse
Instance Method Summary collapse
- #coverage(filepath) ⇒ Object
- #ignored_files ⇒ Object
-
#initialize(lcov_io, opts) ⇒ LcovParser
constructor
A new instance of LcovParser.
- #parse ⇒ Object
- #skipped?(_filepath, _line_no) ⇒ Boolean
- #total_branch_coverage ⇒ Object
- #total_coverage ⇒ Object
Methods included from RootToRelativePaths
Constructor Details
#initialize(lcov_io, opts) ⇒ LcovParser
Returns a new instance of LcovParser.
13 14 15 16 17 |
# File 'lib/undercover/lcov_parser.rb', line 13 def initialize(lcov_io, opts) @io = lcov_io @source_files = {} @code_dir = opts&.path end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
11 12 13 |
# File 'lib/undercover/lcov_parser.rb', line 11 def io @io end |
#source_files ⇒ Object (readonly)
Returns the value of attribute source_files.
11 12 13 |
# File 'lib/undercover/lcov_parser.rb', line 11 def source_files @source_files end |
Class Method Details
.parse(lcov_report_path, opts = nil) ⇒ Object
19 20 21 22 |
# File 'lib/undercover/lcov_parser.rb', line 19 def self.parse(lcov_report_path, opts = nil) lcov_io = File.open(lcov_report_path) new(lcov_io, opts).parse end |
Instance Method Details
#coverage(filepath) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/undercover/lcov_parser.rb', line 30 def coverage(filepath) _filename, coverage = source_files.find do |relative_path, _| relative_path == fix_relative_filepath(filepath) end coverage || [] end |
#ignored_files ⇒ Object
60 61 62 63 |
# File 'lib/undercover/lcov_parser.rb', line 60 def ignored_files # supported by SimplecovResultAdapter only [] end |
#parse ⇒ Object
24 25 26 27 28 |
# File 'lib/undercover/lcov_parser.rb', line 24 def parse io.each(&method(:parse_line)) io.close self end |
#skipped?(_filepath, _line_no) ⇒ Boolean
55 56 57 58 |
# File 'lib/undercover/lcov_parser.rb', line 55 def skipped?(_filepath, _line_no) # this is why lcov parser will be deprecated false end |
#total_branch_coverage ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/undercover/lcov_parser.rb', line 46 def total_branch_coverage all_lines = source_files.values.flatten(1) return 0 if all_lines.empty? all_branches = all_lines.select { _1.size == 4 } total_f = all_branches.select { |_l_no, _block_no, _br_no, hits| hits.positive? }.size.to_f / all_branches.size total_f.round(3) end |
#total_coverage ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/undercover/lcov_parser.rb', line 37 def total_coverage all_lines = source_files.values.flatten(1) return 0 if all_lines.empty? all_lines = all_lines.select { _1.size == 2 } total_f = all_lines.select { |_line_no, hits| hits.positive? }.size.to_f / all_lines.size total_f.round(3) end |