Class: GCOV::File
- Inherits:
-
Object
- Object
- GCOV::File
- Defined in:
- lib/file.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(line) ⇒ Object
- #_update_stats ⇒ Object
- #add_lines(&block) ⇒ Object
-
#initialize(name) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(name) ⇒ File
Returns a new instance of File.
22 23 24 25 26 27 28 29 |
# File 'lib/file.rb', line 22 def initialize name fail "name required" unless name and name.is_a? String @name = name @lines = [] @meta = {} @stats = {} _update_stats end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
20 21 22 |
# File 'lib/file.rb', line 20 def lines @lines end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
20 21 22 |
# File 'lib/file.rb', line 20 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/file.rb', line 20 def name @name end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
20 21 22 |
# File 'lib/file.rb', line 20 def stats @stats end |
Class Method Details
.demangle(filename) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/file.rb', line 88 def self.demangle filename result = filename if start = result.index(/###/) result = result[start..-1] end result.gsub!( /(###|#|\^|\.gcov$)/, {"###"=>"/","#"=>"/","^"=>"..",".gcov"=>""} ) result = ::Pathname.new(result).cleanpath.to_s result end |
Instance Method Details
#<<(line) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/file.rb', line 66 def <<(line) fail "need to be in add_lines block" unless @adding if line.number == 0 key,val = /([^:]+):(.*)$/.match(line.text).to_a[1..2] @meta[key] = val else @lines << line end end |
#_update_stats ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/file.rb', line 39 def _update_stats @stats = { :missed_lines => 0, :exec_lines => 0, :empty_lines => 0, :total_exec => 0, :total_lines => 0, :lines => 0, :coverage => 0.0, :hits_per_line => 0.0 } @lines.each do |line| @stats[:missed_lines] += (line.state == :missed).to_i @stats[:exec_lines] += (line.state == :exec).to_i @stats[:total_exec] += (line.count.is_a?(Integer) ? line.count : 0 ) @stats[:empty_lines] += (line.state == :none).to_i end @stats[:lines] = @stats[:exec_lines] + @stats[:missed_lines] @stats[:total_lines] = @stats[:lines] + @stats[:empty_lines] @stats[:coverage] = @stats[:exec_lines].to_f / @stats[:lines].to_f @stats[:coverage_s] = sprintf("%0.01f%",100.0*@stats[:coverage]) @stats[:hits_per_line] = @stats[:total_exec].to_f / @stats[:lines] @stats[:hits_per_line_s] = sprintf("%0.02f",@stats[:hits_per_line]) end |
#add_lines(&block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/file.rb', line 31 def add_lines &block fail "add_lines requires a block" unless block_given? @adding = true yield @adding = false _update_stats end |