Class: CoverMe::Formatter
- Inherits:
-
Object
- Object
- CoverMe::Formatter
- 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
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#finalize ⇒ Object
Called when all the reports and the index have been formatted.
-
#format(object) ⇒ Object
Given an object, CoverMe::Report or CoverMe::Index it will call the appropriate format method in the subclass.
-
#initialize(options = {}) ⇒ Formatter
constructor
:nodoc:.
-
#template(file) ⇒ Object
Returns an ERB object based on the template file requested.
Constructor Details
#initialize(options = {}) ⇒ Formatter
:nodoc:
14 15 16 |
# File 'lib/cover_me/formatter.rb', line 14 def initialize( = {}) # :nodoc: self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/cover_me/formatter.rb', line 12 def @options end |
Instance Method Details
#finalize ⇒ Object
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 |