Class: CoverMe::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cover_me/formatter.rb

Overview

A base class for implementing formatters of the coverage.

All subclasses must implement the following methods:

def format_report(report)
end

def format_index(index)
end

Direct Known Subclasses

EmmaFormatter, HtmlFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Formatter

:nodoc:



14
15
16
# File 'lib/cover_me/formatter.rb', line 14

def initialize(options = {}) # :nodoc:
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/cover_me/formatter.rb', line 12

def options
  @options
end

Instance Method Details

#finalizeObject

Called when all the reports and the index have been formatted. Usually used for outputting files such as .css and .js files. Can safely be overridden by subclasses



31
32
# File 'lib/cover_me/formatter.rb', line 31

def finalize
end

#format(object) ⇒ Object

Given an object, CoverMe::Report or CoverMe::Index it will call the appropriate format method in the subclass.



20
21
22
23
24
25
26
# File 'lib/cover_me/formatter.rb', line 20

def format(object)
  if object.is_a?(CoverMe::Report)
    return send(:format_report, object)
  elsif object.is_a?(CoverMe::Index)
    return send(:format_index, object)
  end
end

#template(file) ⇒ Object

Returns an ERB object based on the template file requested. Template files are expected to live in the templates directory.

Example:

template('index.html.erb') # => ERB object

The ERB object return still needs to be bound and processed.



41
42
43
# File 'lib/cover_me/formatter.rb', line 41

def template(file)
  ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', file)))
end