Class: Duvet::Covs

Inherits:
Array
  • Object
show all
Defined in:
lib/duvet/covs.rb

Instance Method Summary collapse

Constructor Details

#initialize(cov) ⇒ Covs

Returns a new instance of Covs.



4
5
6
7
8
9
# File 'lib/duvet/covs.rb', line 4

def initialize(cov)
  self.replace []
  cov.each do |path, c|
    self << Cov.new(path, c)
  end
end

Instance Method Details

#dataObject



15
16
17
# File 'lib/duvet/covs.rb', line 15

def data
  { 'files' => map {|i| i.data } }
end

#formatObject



19
20
21
22
# File 'lib/duvet/covs.rb', line 19

def format
  template = (TEMPLATE_PATH + 'html' + 'index.erb').read
  Erubis::Eruby.new(template).result(TEMPLATE_HASH.merge(self.data))
end

#reportObject



11
12
13
# File 'lib/duvet/covs.rb', line 11

def report
  map {|i| i.report }.join('')
end

#write(dir) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/duvet/covs.rb', line 24

def write(dir)
  if size > 0
    FileUtils.mkdir_p(dir)
    File.open(dir + 'index.html', 'w') {|f| f.write(format) }
    
    each {|c| c.write(dir) }
    write_resources(dir)
  else
    warn "No files to create coverage for."
  end
end

#write_resources(dir) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/duvet/covs.rb', line 36

def write_resources(dir)
  Pathname.glob(TEMPLATE_PATH + 'css' + '*').each do |i|
    f = File.new(dir + 'styles.css', 'w')
    f.write Sass::Engine.new(i.read).render
  end

  Pathname.glob(TEMPLATE_PATH + 'js' + '*').each do |i|
    f = File.new(dir + i.basename, 'w')
    f.write(i.read)
  end
end