lib/coco/writer/html_directory.rb in coco-0.10.0 vs lib/coco/writer/html_directory.rb in coco-0.11.0
- old
+ new
@@ -1,39 +1,62 @@
# -*- encoding: utf-8 -*-
module Coco
- # I prepare the coverage/ directory for html files.
+ # Public: I prepare the coverage/ directory for html files.
class HtmlDirectory
- attr_reader :coverage_dir
-
+ COVERAGE_DIR = 'coverage'
+
+ # Public: Initialize a new HtmlDirectory object.
def initialize
- @coverage_dir = 'coverage'
- @css_dir = 'coverage/css'
- @img_dir = 'coverage/img'
- css = File.join($COCO_PATH, 'template/css')
+ css = File.join(Coco::ROOT, 'template/css')
@css_files = Dir.glob(css + '/*')
- img = File.join($COCO_PATH, 'template/img')
+ img = File.join(Coco::ROOT, 'template/img')
@img_files = Dir.glob(img + '/*')
end
-
- # Delete the coverage/ directory
+
+ # Public: Get the name of the directory where the HTML report is
+ # stored.
+ #
+ # Returns String.
+ def coverage_dir
+ COVERAGE_DIR
+ end
+
+ # Public: Delete the directory where the HTML report is stored.
+ #
+ # Returns nothing.
def clean
- FileUtils.remove_dir @coverage_dir if File.exist? @coverage_dir
+ FileUtils.remove_dir(coverage_dir) if File.exist?(coverage_dir)
end
-
+
+ # Public: Make all directories needed to store the HTML report, then
+ # copy media files (css, images, etc.).
+ #
+ # Returns nothing.
def setup
- FileUtils.makedirs @css_dir
- FileUtils.makedirs @img_dir
- FileUtils.cp @css_files, @css_dir
- FileUtils.cp @img_files, @img_dir
+ FileUtils.makedirs(css_dir)
+ FileUtils.makedirs(image_dir)
+ FileUtils.cp(@css_files, css_dir)
+ FileUtils.cp(@img_files, image_dir)
end
-
- # I list the html files from the coverage directory
+
+ # Public: I list the html files from the directory where the HTML
+ # report is stored.
+ #
+ # Returns nothing.
def list
- files = Dir.glob("#{@coverage_dir}/*.html")
- files.map {|file| File.basename(file)}
+ files = Dir.glob("#{coverage_dir}/*.html")
+ files.map {|file| File.basename(file) }
end
-
- end
+ private
+
+ def css_dir
+ "#{COVERAGE_DIR}/css"
+ end
+
+ def image_dir
+ "#{COVERAGE_DIR}/img"
+ end
+ end
end