Module: R19Cov::Report::HTML::Page
- Included in:
- DetailPage, IndexPage
- Defined in:
- lib/r19cov/report/html/page.rb
Constant Summary collapse
- PERCENTAGE_RATE =
100.0
- PERCENTAGE_FORMAT_DIGIT =
2
- MAX_FILENAME_SIZE =
70
Instance Method Summary collapse
- #coverage_class(coverage) ⇒ Object
- #filename_format(filename) ⇒ Object
- #generated_on ⇒ Object
- #get_binding ⇒ Object
- #html(page) ⇒ Object
- #html_file(filename) ⇒ Object
- #html_path(filename) ⇒ Object
- #line_format(line) ⇒ Object
- #output_dir ⇒ Object
- #percentage_bar(rate) ⇒ Object
- #percentage_format(value) ⇒ Object
- #raw_options ⇒ Object
- #targets ⇒ Object
- #template(page) ⇒ Object
Instance Method Details
#coverage_class(coverage) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/r19cov/report/html/page.rb', line 81 def coverage_class(coverage) if coverage.nil? "non" elsif coverage >= 1 "covered" elsif coverage == 0 "uncovered" end end |
#filename_format(filename) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/r19cov/report/html/page.rb', line 41 def filename_format(filename) current_dir = Dir.pwd filename = filename.sub(%r|^#{current_dir}|, '.') if filename.size > MAX_FILENAME_SIZE "..." + filename[filename.size - MAX_FILENAME_SIZE .. -1] else filename end end |
#generated_on ⇒ Object
61 62 63 |
# File 'lib/r19cov/report/html/page.rb', line 61 def generated_on Time.now end |
#get_binding ⇒ Object
57 58 59 |
# File 'lib/r19cov/report/html/page.rb', line 57 def get_binding binding end |
#html(page) ⇒ Object
16 17 18 |
# File 'lib/r19cov/report/html/page.rb', line 16 def html(page) ERB.new(template(page)).result(get_binding) end |
#html_file(filename) ⇒ Object
20 21 22 |
# File 'lib/r19cov/report/html/page.rb', line 20 def html_file(filename) File.join(output_dir, html_path(filename)) end |
#html_path(filename) ⇒ Object
11 12 13 14 |
# File 'lib/r19cov/report/html/page.rb', line 11 def html_path(filename) Pathname.new(filename).cleanpath.to_s.gsub(%r|^\w:[/\\]|, '').gsub(/\./, '_').\ gsub(%r|[\\\/]|, '-') + ".html" end |
#line_format(line) ⇒ Object
52 53 54 55 |
# File 'lib/r19cov/report/html/page.rb', line 52 def line_format(line) line = ' ' if line == '' CGI::escapeHTML(line) end |
#output_dir ⇒ Object
32 33 34 |
# File 'lib/r19cov/report/html/page.rb', line 32 def output_dir .output_dir end |
#percentage_bar(rate) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/r19cov/report/html/page.rb', line 65 def (rate) rate = rate * PERCENTAGE_RATE <<-HTML <div class="percentage_bar"> <div class="covered" style="width:#{rate.to_i}px;"></div> <div class="uncovered" style="width:#{100 - rate.to_i}px;"></div> </div> HTML end |
#percentage_format(value) ⇒ Object
75 76 77 78 79 |
# File 'lib/r19cov/report/html/page.rb', line 75 def percentage_format(value) value = ((value * (10 ** PERCENTAGE_FORMAT_DIGIT) * PERCENTAGE_RATE)).ceil.to_f / (10 ** PERCENTAGE_FORMAT_DIGIT).to_f "#{value}%" end |
#raw_options ⇒ Object
28 29 30 |
# File 'lib/r19cov/report/html/page.rb', line 28 def ..join(' ') end |
#targets ⇒ Object
24 25 26 |
# File 'lib/r19cov/report/html/page.rb', line 24 def targets .targets.join(', ') end |
#template(page) ⇒ Object
36 37 38 39 |
# File 'lib/r19cov/report/html/page.rb', line 36 def template(page) template_file = File.join(File.dirname(__FILE__), 'templates', "#{page}.html.erb") File.read(template_file) end |