class Pf2::Reporter::Annotate
Constants
- HitCount
- SourceCodeHits
Public Class Methods
Source
# File lib/pf2/reporter/annotate.rb, line 11 def initialize(profile, source_directory) @profile = profile @source_directory = source_directory end
@param profile [Hash] @param source_directory [String]
Public Instance Methods
Source
# File lib/pf2/reporter/annotate.rb, line 16 def annotate tallied = tally_by_source_code_line(@profile) # Print the source code with hit counts tallied.each do |path, source_code_hits| expanded_path = File.expand_path(path, @source_directory) if !File.exist?(expanded_path) if ignorable_path?(path) puts "Ignoring file: #{path}" else puts "File not found: #{path}" end puts "" puts "" next end source_file = File.open(expanded_path, "r") puts expanded_path puts "" # Print in tabular format # Header row puts " ttl self │" source_file.each_line.with_index(1) do |line, lineno| hits = source_code_hits.line_count[lineno] if !hits.nil? # If any samples are captured for this line puts "%5d %5d │ %s" % [hits.total, hits.self, line.chomp] else puts "%5s %5s │ %s" % ["", "", line.chomp] end end puts "" puts "" ensure source_file.close if source_file end end