Class: MetricFu::Base::Generator
- Inherits:
-
Object
- Object
- MetricFu::Base::Generator
show all
- Defined in:
- lib/metric_fu/base.rb
Overview
Base class for report Generators
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
23
24
25
|
# File 'lib/metric_fu/base.rb', line 23
def initialize(options={})
@base_dir = self.class.metric_dir
end
|
Class Method Details
.generate_report(options = {}) ⇒ Object
35
36
37
38
|
# File 'lib/metric_fu/base.rb', line 35
def self.generate_report(options={})
FileUtils.mkdir_p(metric_dir, :verbose => false) unless File.directory?(metric_dir)
self.new(options).generate_report
end
|
.metric_dir ⇒ Object
27
28
29
|
# File 'lib/metric_fu/base.rb', line 27
def self.metric_dir
File.join(BASE_DIRECTORY, template_name)
end
|
.template_name ⇒ Object
31
32
33
|
# File 'lib/metric_fu/base.rb', line 31
def self.template_name
self.to_s.split('::').last.downcase
end
|
Instance Method Details
#cycle(first_value, second_value, iteration) ⇒ Object
79
80
81
82
|
# File 'lib/metric_fu/base.rb', line 79
def cycle(first_value, second_value, iteration)
return first_value if iteration % 2 == 0
return second_value
end
|
#generate_html ⇒ Object
50
51
52
53
|
# File 'lib/metric_fu/base.rb', line 50
def generate_html
analyze
html = ERB.new(File.read(template_file)).result(binding)
end
|
#generate_report ⇒ Object
46
47
48
|
# File 'lib/metric_fu/base.rb', line 46
def generate_report
save_html(generate_html)
end
|
#inline_css(css) ⇒ Object
66
67
68
|
# File 'lib/metric_fu/base.rb', line 66
def inline_css(css)
open(File.join(MetricFu::TEMPLATE_DIR, css)) { |f| f.read }
end
|
#link_to_filename(name, line = nil) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/metric_fu/base.rb', line 70
def link_to_filename(name, line = nil)
filename = File.expand_path(name)
if PLATFORM['darwin']
%{<a href="txmt://open/?url=file://#{filename}&line=#{line}">#{name}:#{line}</a>}
else
%{<a href="file://#{filename}">#{name}:#{line}</a>}
end
end
|
#save_html(content, file = 'index.html') ⇒ Object
40
41
42
43
44
|
# File 'lib/metric_fu/base.rb', line 40
def save_html(content, file='index.html')
open("#{@base_dir}/#{file}", "w") do |f|
f.puts content
end
end
|
#template_file ⇒ Object
59
60
61
|
# File 'lib/metric_fu/base.rb', line 59
def template_file
File.join(MetricFu::TEMPLATE_DIR, "#{template_name}.html.erb")
end
|
#template_name ⇒ Object
55
56
57
|
# File 'lib/metric_fu/base.rb', line 55
def template_name
self.class.template_name
end
|