Class: Duvet::Cov
- Inherits:
-
Object
- Object
- Duvet::Cov
- Defined in:
- lib/duvet/cov.rb
Overview
A single file along with coverage data.
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#code_coverage ⇒ Float
Gives a real number between 0 and 1 indicating how many lines of code have been executed.
-
#code_lines ⇒ Array
Coverage data for all the lines which can be executed.
-
#data ⇒ Hash
Data for templating.
-
#initialize(path, cov) ⇒ Cov
constructor
A new instance of Cov.
-
#lines ⇒ Array
Coverage data of lines in the file.
-
#percent(num) ⇒ String
The number formatted as a percentage, ??.??%.
-
#ran_lines ⇒ Array
Coverage data for all the lines which have been ran.
-
#report ⇒ String
A simple text report of coverage.
-
#total_coverage ⇒ Float
Gives a real number between 0 and 1 indicating how many lines have been executed.
-
#write ⇒ Object
Writes the file.
Constructor Details
#initialize(path, cov) ⇒ Cov
Returns a new instance of Cov.
7 8 9 10 11 12 13 14 |
# File 'lib/duvet/cov.rb', line 7 def initialize(path, cov) @path = Pathname.new(path) if @path.to_s.include?(Dir.pwd) @path = @path.relative_path_from(Pathname.getwd) end @cov = cov end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/duvet/cov.rb', line 5 def path @path end |
Instance Method Details
#code_coverage ⇒ Float
Gives a real number between 0 and 1 indicating how many lines of code have been executed. It ignores all lines that can not be executed such as comments.
45 46 47 48 |
# File 'lib/duvet/cov.rb', line 45 def code_coverage return 0.0 if code_lines.size.zero? ran_lines.size.to_f / code_lines.size.to_f end |
#code_lines ⇒ Array
Returns Coverage data for all the lines which can be executed.
22 23 24 |
# File 'lib/duvet/cov.rb', line 22 def code_lines lines.reject {|i| i.nil?} end |
#data ⇒ Hash
Returns Data for templating.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/duvet/cov.rb', line 66 def data { file: { path: @path.to_s, url: @path.to_s[0..-@path.extname.size] + 'html', root: '../' * @path.to_s.count('/'), source: @path.readlines, }, lines: { total: lines.size, code: code_lines.size, ran: ran_lines.size }, coverage: { code: percent(code_coverage), total: percent(total_coverage), lines: lines } } end |
#lines ⇒ Array
Returns Coverage data of lines in the file.
17 18 19 |
# File 'lib/duvet/cov.rb', line 17 def lines @cov end |
#percent(num) ⇒ String
Returns The number formatted as a percentage, ??.??%.
52 53 54 |
# File 'lib/duvet/cov.rb', line 52 def percent(num) "%.2f%" % (num * 100) end |
#ran_lines ⇒ Array
Returns Coverage data for all the lines which have been ran.
27 28 29 |
# File 'lib/duvet/cov.rb', line 27 def ran_lines code_lines.reject {|i| i.zero?} end |
#report ⇒ String
Returns A simple text report of coverage.
57 58 59 60 61 62 63 |
# File 'lib/duvet/cov.rb', line 57 def report <<EOS #{@path} total: #{percent(total_coverage)} code: #{percent(code_coverage)} EOS end |
#total_coverage ⇒ Float
Gives a real number between 0 and 1 indicating how many lines have been executed.
35 36 37 38 |
# File 'lib/duvet/cov.rb', line 35 def total_coverage return 0.0 if lines.size.zero? ran_lines.size.to_f / lines.size.to_f end |