Class: Coverage::HTMLPrinter::Detail

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utility
Defined in:
lib/coverage/html_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#coverage_bar, #javascript, #stylesheet

Constructor Details

#initialize(path_settings, project_name, path, counts) ⇒ Detail

Returns a new instance of Detail.



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/coverage/html_printer.rb', line 155

def initialize(path_settings, project_name, path, counts)
  @path_settings = path_settings
  @project_name = project_name
  @path = path
  @counts = counts
  @statistics = Coverage::Statistics.new(path, counts)
  @source = Pathname(path)
  @page_title = @source.basename
  @sources = []
  @source.each_line.with_index.zip(@counts) do |(line, index), count|
    @sources << Line.new(index + 1, line, count)
  end
end

Instance Attribute Details

#page_titleObject (readonly)

Returns the value of attribute page_title.



153
154
155
# File 'lib/coverage/html_printer.rb', line 153

def page_title
  @page_title
end

#pathObject (readonly)

Returns the value of attribute path.



153
154
155
# File 'lib/coverage/html_printer.rb', line 153

def path
  @path
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



153
154
155
# File 'lib/coverage/html_printer.rb', line 153

def project_name
  @project_name
end

Instance Method Details

#code_coverageObject



203
204
205
# File 'lib/coverage/html_printer.rb', line 203

def code_coverage
  coverage_bar(@statistics.code_coverage)
end

#each_lineObject



179
180
181
182
183
# File 'lib/coverage/html_printer.rb', line 179

def each_line
  @sources.each do |line|
    yield line
  end
end

#html_filenameObject



193
194
195
196
197
# File 'lib/coverage/html_printer.rb', line 193

def html_filename
  dir = @source.sub(Regexp.new(@path_settings.base_directory.to_s), '.').dirname
  file = @source.basename.sub(/\.rb/, "_rb.html")
  dir + file
end

#labelObject



185
186
187
# File 'lib/coverage/html_printer.rb', line 185

def label
  @label ||= @source.relative_path_from(@path_settings.output_directory).to_s.sub(/\A\.\.\//, '')
end


189
190
191
# File 'lib/coverage/html_printer.rb', line 189

def link
  %Q!<a href="#{html_filename}">#{label}</a>!
end


169
170
171
172
173
174
175
176
177
# File 'lib/coverage/html_printer.rb', line 169

def print
  erb = ERB.new(File.read(template_path), nil, '-')
  path = @path_settings.output_directory + html_filename
  erb.filename = path.to_s
  FileUtils.mkdir_p(path.dirname)
  File.open(path, "wb+") do |file|
    file.puts(erb.result(binding))
  end
end

#total_coverageObject



199
200
201
# File 'lib/coverage/html_printer.rb', line 199

def total_coverage
  coverage_bar(@statistics.total_coverage)
end