Class: DeepCover::Reporter::HTML::Source
- Inherits:
-
Struct
- Object
- Struct
- DeepCover::Reporter::HTML::Source
- Includes:
- Base, Tools::Covered
- Defined in:
- lib/deep_cover/reporter/html/source.rb
Instance Attribute Summary collapse
-
#analyser_map ⇒ Object
Returns the value of attribute analyser_map.
-
#partial_path ⇒ Object
Returns the value of attribute partial_path.
Instance Method Summary collapse
- #analyser ⇒ Object
- #convert_source ⇒ Object
- #covered_code ⇒ Object
- #format_source ⇒ Object
-
#initialize(analyser_map, partial_path) ⇒ Source
constructor
A new instance of Source.
- #root_path ⇒ Object
- #stats ⇒ Object
Methods included from Base
Methods included from Tools::ContentTag
Methods included from Tools::Covered
Constructor Details
Instance Attribute Details
#analyser_map ⇒ Object
Returns the value of attribute analyser_map
7 8 9 |
# File 'lib/deep_cover/reporter/html/source.rb', line 7 def analyser_map @analyser_map end |
#partial_path ⇒ Object
Returns the value of attribute partial_path
7 8 9 |
# File 'lib/deep_cover/reporter/html/source.rb', line 7 def partial_path @partial_path end |
Instance Method Details
#analyser ⇒ Object
51 52 53 |
# File 'lib/deep_cover/reporter/html/source.rb', line 51 def analyser analyser_map[:per_char] end |
#convert_source ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/deep_cover/reporter/html/source.rb', line 27 def convert_source @rewriter = Parser::Source::TreeRewriter.new(covered_code.buffer) html_escape @rewriter.process end |
#covered_code ⇒ Object
55 56 57 |
# File 'lib/deep_cover/reporter/html/source.rb', line 55 def covered_code analyser.covered_code end |
#format_source ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/deep_cover/reporter/html/source.rb', line 17 def format_source lines = convert_source.split("\n") lines.map { |line| content_tag(:td, line) } rows = lines.map.with_index do |line, i| nb = content_tag(:td, i + 1, id: "L#{i + 1}", class: :nb) content_tag(:tr, nb + content_tag(:td, line)) end content_tag(:table, rows.join, class: :source) end |
#root_path ⇒ Object
35 36 37 |
# File 'lib/deep_cover/reporter/html/source.rb', line 35 def root_path Pathname('.').relative_path_from(Pathname(partial_path).dirname) end |
#stats ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deep_cover/reporter/html/source.rb', line 39 def stats cells = analyser_map.map do |type, analyser| data = analyser.stats f = ->(kind) { content_tag(:span, data.public_send(kind), class: kind, title: kind) } [content_tag(:th, analyser.class.human_name, class: type), content_tag(:td, "#{f[:executed]} #{f[:ignored] if data.ignored > 0} / #{f[:potentially_executable]}", class: type), ] end rows = cells.transpose.map { |line| content_tag(:tr, line.join) } content_tag(:table, rows.join) end |