Class: DeepCover::Reporter::HTML::Source

Inherits:
Struct
  • Object
show all
Includes:
Base, Tools::Covered
Defined in:
lib/deep_cover/reporter/html/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#setup

Methods included from Tools::ContentTag

#content_tag

Methods included from Tools::Covered

#covered?

Constructor Details

#initialize(analyser_map, partial_path) ⇒ Source

Returns a new instance of Source.

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/deep_cover/reporter/html/source.rb', line 10

def initialize(analyser_map, partial_path)
  raise ArgumentError unless analyser_map.values.all? { |a| a.is_a?(Analyser) }
  super
end

Instance Attribute Details

#analyser_mapObject

Returns the value of attribute analyser_map

Returns:

  • (Object)

    the current value of analyser_map



7
8
9
# File 'lib/deep_cover/reporter/html/source.rb', line 7

def analyser_map
  @analyser_map
end

#partial_pathObject

Returns the value of attribute partial_path

Returns:

  • (Object)

    the current value of partial_path



7
8
9
# File 'lib/deep_cover/reporter/html/source.rb', line 7

def partial_path
  @partial_path
end

Instance Method Details

#analyserObject



51
52
53
# File 'lib/deep_cover/reporter/html/source.rb', line 51

def analyser
  analyser_map[:per_char]
end

#convert_sourceObject



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)
  insert_node_tags
  insert_branch_tags
  html_escape
  @rewriter.process
end

#covered_codeObject



55
56
57
# File 'lib/deep_cover/reporter/html/source.rb', line 55

def covered_code
  analyser.covered_code
end

#format_sourceObject



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| (:td, line) }
  rows = lines.map.with_index do |line, i|
    nb = (:td, i + 1, id: "L#{i + 1}", class: :nb)
    (:tr, nb + (:td, line))
  end
  (:table, rows.join, class: :source)
end

#root_pathObject



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

#statsObject



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) { (:span, data.public_send(kind), class: kind, title: kind) }
    [(:th, analyser.class.human_name, class: type),
     (:td, "#{f[:executed]} #{f[:ignored] if data.ignored > 0} / #{f[:potentially_executable]}", class: type),
    ]
  end
  rows = cells.transpose.map { |line| (:tr, line.join) }
  (:table, rows.join)
end