nielsm-metric_fu 0.9.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/HISTORY +38 -0
  2. data/README +1 -154
  3. data/Rakefile +9 -2
  4. data/TODO +3 -3
  5. data/lib/base/base_template.rb +146 -0
  6. data/lib/base/configuration.rb +207 -0
  7. data/lib/base/generator.rb +160 -0
  8. data/lib/base/graph.rb +37 -0
  9. data/lib/{metric_fu → base}/md5_tracker.rb +0 -0
  10. data/lib/base/report.rb +100 -0
  11. data/lib/{metric_fu → generators}/churn.rb +26 -23
  12. data/lib/generators/flay.rb +34 -0
  13. data/lib/generators/flog.rb +140 -0
  14. data/lib/generators/rcov.rb +87 -0
  15. data/lib/generators/reek.rb +37 -0
  16. data/lib/generators/roodi.rb +31 -0
  17. data/lib/generators/saikuro.rb +208 -0
  18. data/lib/generators/stats.rb +43 -0
  19. data/lib/graphs/flay_grapher.rb +34 -0
  20. data/lib/graphs/flog_grapher.rb +37 -0
  21. data/lib/graphs/rcov_grapher.rb +34 -0
  22. data/lib/graphs/reek_grapher.rb +44 -0
  23. data/lib/graphs/roodi_grapher.rb +34 -0
  24. data/lib/metric_fu.rb +24 -3
  25. data/lib/templates/awesome/awesome_template.rb +30 -0
  26. data/lib/templates/awesome/churn.html.erb +19 -0
  27. data/lib/templates/awesome/default.css +75 -0
  28. data/lib/templates/awesome/flay.html.erb +27 -0
  29. data/lib/templates/awesome/flog.html.erb +46 -0
  30. data/lib/templates/awesome/index.html.erb +28 -0
  31. data/lib/templates/awesome/layout.html.erb +27 -0
  32. data/lib/templates/awesome/rcov.html.erb +36 -0
  33. data/lib/templates/awesome/reek.html.erb +34 -0
  34. data/lib/templates/awesome/roodi.html.erb +21 -0
  35. data/lib/templates/awesome/saikuro.html.erb +71 -0
  36. data/lib/templates/awesome/stats.html.erb +41 -0
  37. data/lib/templates/{churn.html.erb → standard/churn.html.erb} +13 -4
  38. data/lib/templates/{default.css → standard/default.css} +20 -1
  39. data/lib/templates/{flay.html.erb → standard/flay.html.erb} +13 -9
  40. data/lib/templates/standard/flog.html.erb +53 -0
  41. data/lib/templates/standard/index.html.erb +38 -0
  42. data/lib/templates/standard/rcov.html.erb +43 -0
  43. data/lib/templates/standard/reek.html.erb +42 -0
  44. data/lib/templates/{roodi.html.erb → standard/roodi.html.erb} +11 -8
  45. data/lib/templates/standard/saikuro.html.erb +84 -0
  46. data/lib/templates/standard/standard_template.rb +26 -0
  47. data/lib/templates/standard/stats.html.erb +55 -0
  48. data/spec/base/base_template_spec.rb +161 -0
  49. data/spec/base/configuration_spec.rb +303 -0
  50. data/spec/base/generator_spec.rb +181 -0
  51. data/spec/{md5_tracker_spec.rb → base/md5_tracker_spec.rb} +1 -1
  52. data/spec/base/report_spec.rb +139 -0
  53. data/spec/generators/churn_spec.rb +152 -0
  54. data/spec/generators/flay_spec.rb +104 -0
  55. data/spec/generators/flog_spec.rb +219 -0
  56. data/spec/generators/reek_spec.rb +60 -0
  57. data/spec/generators/saikuro_spec.rb +58 -0
  58. data/spec/generators/stats_spec.rb +74 -0
  59. data/spec/graphs/flog_grapher_spec.rb +15 -0
  60. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  61. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  62. data/spec/resources/saikuro/index_cyclo.html +155 -0
  63. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +10 -0
  64. data/spec/spec.opts +8 -0
  65. data/spec/spec_helper.rb +24 -7
  66. data/tasks/metric_fu.rake +22 -0
  67. data/vendor/_fonts/monaco.ttf +0 -0
  68. data/{lib/metric_fu → vendor}/saikuro/saikuro.rb +0 -0
  69. metadata +84 -66
  70. data/lib/metric_fu/base.rb +0 -160
  71. data/lib/metric_fu/flay.rb +0 -17
  72. data/lib/metric_fu/flog.rb +0 -129
  73. data/lib/metric_fu/reek.rb +0 -17
  74. data/lib/metric_fu/roodi.rb +0 -17
  75. data/lib/tasks/churn.rake +0 -9
  76. data/lib/tasks/coverage.rake +0 -54
  77. data/lib/tasks/flay.rake +0 -6
  78. data/lib/tasks/flog.rake +0 -69
  79. data/lib/tasks/metric_fu.rake +0 -24
  80. data/lib/tasks/metric_fu.rb +0 -6
  81. data/lib/tasks/railroad.rake +0 -39
  82. data/lib/tasks/reek.rake +0 -6
  83. data/lib/tasks/roodi.rake +0 -7
  84. data/lib/tasks/saikuro.rake +0 -35
  85. data/lib/tasks/stats.rake +0 -14
  86. data/lib/templates/flog.html.erb +0 -38
  87. data/lib/templates/flog_page.html.erb +0 -25
  88. data/lib/templates/reek.html.erb +0 -30
  89. data/spec/base_spec.rb +0 -57
  90. data/spec/churn_spec.rb +0 -117
  91. data/spec/config_spec.rb +0 -110
  92. data/spec/flay_spec.rb +0 -19
  93. data/spec/flog_spec.rb +0 -208
  94. data/spec/reek_spec.rb +0 -26
@@ -0,0 +1,160 @@
1
+ module MetricFu
2
+
3
+ # = Generator
4
+ #
5
+ # The Generator class is an abstract class that provides the
6
+ # skeleton for producing different types of metrics.
7
+ #
8
+ # It drives the production of the metrics through a template
9
+ # method - #generate_report(options={}). This method calls
10
+ # #emit, #analyze and #to_h in order to produce the metrics.
11
+ #
12
+ # To implement a concrete class to generate a metric, therefore,
13
+ # the class must implement those three methods.
14
+ #
15
+ # * #emit should take care of running the metric tool and
16
+ # gathering its output.
17
+ # * #analyze should take care of manipulating the output from
18
+ # #emit and making it possible to store it in a programmatic way.
19
+ # * #to_h should provide a hash representation of the output from
20
+ # #analyze ready to be serialized into yaml at some point.
21
+ #
22
+ # == Pre-conditions
23
+ #
24
+ # Based on the class name of the concrete class implementing a
25
+ # Generator, the Generator class will create a 'metric_directory'
26
+ # named after the class under the MetricFu.scratch_directory, where
27
+ # any output from the #emit method should go.
28
+ #
29
+ # It will also create the MetricFu.output_directory if neccessary, and
30
+ # in general setup the directory structure that the MetricFu system
31
+ # expects.
32
+ class Generator
33
+ attr_reader :report, :template
34
+
35
+ def initialize(options={})
36
+ self.class.verify_dependencies!
37
+ create_metric_dir_if_missing
38
+ create_output_dir_if_missing
39
+ create_data_dir_if_missing
40
+ end
41
+
42
+ # Creates a new generator and returns the output of the
43
+ # #generate_report method. This is the typical way to
44
+ # generate a new MetricFu report. For more information see
45
+ # the #generate_report instance method.
46
+ #
47
+ # @params options Hash
48
+ # A currently unused hash to configure the Generator
49
+ #
50
+ # @see generate_report
51
+ def self.generate_report(options={})
52
+ generator = self.new(options)
53
+ generator.generate_report
54
+ end
55
+
56
+ # Provides the unqualified class name of an implemented concrete
57
+ # class, as a string. For example:
58
+ #
59
+ # class Flay < Generator; end
60
+ # klass = Flay.new
61
+ # klass.class_name
62
+ # > "flay"
63
+ #
64
+ # @return String
65
+ # The unqualified class name of this concrete class, returned
66
+ # as a string.
67
+ def self.class_name
68
+ self.to_s.split('::').last.downcase
69
+ end
70
+
71
+ # Returns the directory where the Generator will write any output
72
+ def self.metric_directory
73
+ File.join(MetricFu.scratch_directory, class_name)
74
+ end
75
+
76
+ def create_metric_dir_if_missing #:nodoc:
77
+ unless File.directory?(metric_directory)
78
+ FileUtils.mkdir_p(metric_directory, :verbose => false)
79
+ end
80
+ end
81
+
82
+ def create_output_dir_if_missing #:nodoc:
83
+ unless File.directory?(MetricFu.output_directory)
84
+ FileUtils.mkdir_p(MetricFu.output_directory, :verbose => false)
85
+ end
86
+ end
87
+
88
+ def create_data_dir_if_missing #:nodoc:
89
+ unless File.directory?(MetricFu.data_directory)
90
+ FileUtils.mkdir_p(MetricFu.data_directory, :verbose => false)
91
+ end
92
+ end
93
+
94
+ # @return String
95
+ # The path of the metric directory this class is using.
96
+ def metric_directory
97
+ self.class.metric_directory
98
+ end
99
+
100
+
101
+ # Defines some hook methods for the concrete classes to hook into.
102
+ %w[emit analyze].each do |meth|
103
+ define_method("before_#{meth}".to_sym) {}
104
+ define_method("after_#{meth}".to_sym) {}
105
+ end
106
+ define_method("before_to_h".to_sym) {}
107
+
108
+ # Provides a template method to drive the production of a metric
109
+ # from a concrete implementation of this class. Each concrete
110
+ # class must implement the three methods that this template method
111
+ # calls: #emit, #analyze and #to_h. For more details, see the
112
+ # class documentation.
113
+ #
114
+ # This template method also calls before_emit, after_emit... etc.
115
+ # methods to allow extra hooks into the processing methods, and help
116
+ # to keep the logic of your Generators clean.
117
+ def generate_report
118
+ %w[emit analyze].each do |meth|
119
+ send("before_#{meth}".to_sym)
120
+ send("#{meth}".to_sym)
121
+ send("after_#{meth}".to_sym)
122
+ end
123
+ before_to_h()
124
+ to_h()
125
+ end
126
+
127
+ def round_to_tenths(decimal)
128
+ (decimal * 10).round / 10.0
129
+ end
130
+
131
+ # Allows subclasses to check for required gems
132
+ def self.verify_dependencies!
133
+ true
134
+ end
135
+
136
+ def emit #:nodoc:
137
+ raise <<-EOF
138
+ This method must be implemented by a concrete class descending
139
+ from Generator. See generator class documentation for more
140
+ information.
141
+ EOF
142
+ end
143
+
144
+ def analyze #:nodoc:
145
+ raise <<-EOF
146
+ This method must be implemented by a concrete class descending
147
+ from Generator. See generator class documentation for more
148
+ information.
149
+ EOF
150
+ end
151
+
152
+ def to_graph #:nodoc:
153
+ raise <<-EOF
154
+ This method must be implemented by a concrete class descending
155
+ from Generator. See generator class documentation for more
156
+ information.
157
+ EOF
158
+ end
159
+ end
160
+ end
data/lib/base/graph.rb ADDED
@@ -0,0 +1,37 @@
1
+ module MetricFu
2
+
3
+ def self.graph
4
+ @graph ||= Graph.new
5
+ end
6
+
7
+ class Graph
8
+
9
+ attr_accessor :clazz
10
+
11
+ def initialize
12
+ self.clazz = []
13
+ end
14
+
15
+ def add(graph_type)
16
+ grapher_name = graph_type.to_s.capitalize + "Grapher"
17
+ self.clazz.push MetricFu.const_get(grapher_name).new
18
+ end
19
+
20
+
21
+ def generate
22
+ puts "Generating graphs"
23
+ Dir[File.join(MetricFu.data_directory, '*.yml')].sort.each do |metric_file|
24
+ puts "Generating graphs for #{metric_file}"
25
+ date = metric_file.split('/')[3].split('.')[0]
26
+ metrics = YAML::load(File.open(metric_file))
27
+
28
+ self.clazz.each do |grapher|
29
+ grapher.get_metrics(metrics, date)
30
+ end
31
+ end
32
+ self.clazz.each do |grapher|
33
+ grapher.graph!
34
+ end
35
+ end
36
+ end
37
+ end
File without changes
@@ -0,0 +1,100 @@
1
+ module MetricFu
2
+
3
+ # MetricFu.report memoizes access to a Report object, that will be
4
+ # used throughout the lifecycle of the MetricFu app.
5
+ def self.report
6
+ @report ||= Report.new
7
+ end
8
+
9
+ # = Report
10
+ #
11
+ # The Report class is responsible two things:
12
+ #
13
+ # It adds information to the yaml report, produced by the system
14
+ # as a whole, for each of the generators used in this test run.
15
+ #
16
+ # It also handles passing the information from each generator used
17
+ # in this test run out to the template class set in
18
+ # MetricFu::Configuration.
19
+ class Report
20
+
21
+ # Renders the result of the report_hash into a yaml serialization
22
+ # ready for writing out to a file.
23
+ #
24
+ # @return YAML
25
+ # A YAML object containing the results of the report generation
26
+ # process
27
+ def to_yaml
28
+ report_hash.to_yaml
29
+ end
30
+
31
+
32
+ def report_hash #:nodoc:
33
+ @report_hash ||= {}
34
+ end
35
+
36
+ # Instantiates a new template class based on the configuration set
37
+ # in MetricFu::Configuration, or through the MetricFu.config block
38
+ # in your rake file (defaults to the included StandardTemplate) and
39
+ # assigns the report_hash to the report_hash to the template and
40
+ # asks itself to write itself out.
41
+ def save_templatized_report
42
+ @template = MetricFu.template_class.new
43
+ @template.report = report_hash
44
+ @template.write
45
+ end
46
+
47
+ # Adds a hash from a passed report, produced by one of the Generator
48
+ # classes to the aggregate report_hash managed by this hash.
49
+ #
50
+ # @param report_type Hash
51
+ # The hash to add to the aggregate report_hash
52
+ def add(report_type)
53
+ clazz = MetricFu.const_get(report_type.to_s.capitalize)
54
+ report_hash.merge!(clazz.generate_report)
55
+ end
56
+
57
+ # Saves the passed in content to the passed in directory. If
58
+ # a filename is passed in it will be used as the name of the
59
+ # file, otherwise it will default to 'index.html'
60
+ #
61
+ # @param content String
62
+ # A string containing the content (usually html) to be written
63
+ # to the file.
64
+ #
65
+ # @param dir String
66
+ # A dir containing the path to the directory to write the file in.
67
+ #
68
+ # @param file String
69
+ # A filename to save the path as. Defaults to 'index.html'.
70
+ #
71
+ def save_output(content, dir, file='index.html')
72
+ open("#{dir}/#{file}", "w") do |f|
73
+ f.puts content
74
+ end
75
+ end
76
+
77
+ # Checks to discover whether we should try and open the results
78
+ # of the report in the browser on this system. We only try and open
79
+ # in the browser if we're on OS X and we're not running in a
80
+ # CruiseControl.rb environment. See MetricFu.configuration for more
81
+ # details about how we make those guesses.
82
+ #
83
+ # @return Boolean
84
+ # Should we open in the browser or not?
85
+ def open_in_browser?
86
+ MetricFu.configuration.platform.include?('darwin') &&
87
+ ! MetricFu.configuration.is_cruise_control_rb?
88
+ end
89
+
90
+ # Shows 'index.html' from the passed directory in the browser
91
+ # if we're able to open the browser on this platform.
92
+ #
93
+ # @param dir String
94
+ # The directory path where the 'index.html' we want to open is
95
+ # stored
96
+ def show_in_browser(dir)
97
+ system("open #{dir}/index.html") if open_in_browser?
98
+ end
99
+ end
100
+ end
@@ -1,27 +1,37 @@
1
+ require 'chronic'
2
+ require 'generator'
1
3
  module MetricFu
2
4
 
3
- def self.generate_churn_report
4
- Churn.generate_report(MetricFu.churn)
5
- system("open #{Churn.metric_dir}/index.html") if open_in_browser?
6
- end
7
-
8
- class Churn < Base::Generator
5
+ class Churn < Generator
9
6
 
7
+
10
8
  def initialize(options={})
11
- @base_dir = File.join(MetricFu::BASE_DIRECTORY, template_name)
12
- if File.exist?(".git")
13
- @source_control = Git.new(options[:start_date])
9
+ super
10
+ if self.class.git?
11
+ @source_control = Git.new(MetricFu.churn[:start_date])
14
12
  elsif File.exist?(".svn")
15
- @source_control = Svn.new(options[:start_date])
13
+ @source_control = Svn.new(MetricFu.churn[:start_date])
16
14
  else
17
15
  raise "Churning requires a subversion or git repo"
18
16
  end
17
+ @minimum_churn_count = MetricFu.churn[:minimum_churn_count] || 5
18
+ end
19
19
 
20
- @minimum_churn_count = options[:minimum_churn_count] || 5
20
+ def self.git?
21
+ system("git branch")
22
+ end
23
+
24
+ def emit
25
+ @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count}
21
26
  end
22
27
 
23
28
  def analyze
24
- @changes = parse_log_for_changes.reject! {|file, change_count| change_count < @minimum_churn_count}
29
+ @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]}
30
+ @changes = @changes.map {|change| {:file_path => change[0], :times_changed => change[1] }}
31
+ end
32
+
33
+ def to_h
34
+ {:churn => {:changes => @changes}}
25
35
  end
26
36
 
27
37
  private
@@ -41,13 +51,6 @@ module MetricFu
41
51
  def initialize(start_date=nil)
42
52
  @start_date = start_date
43
53
  end
44
-
45
- private
46
- def require_rails_env
47
- # not sure if the following works because active_support might only be in vendor/rails
48
- # require 'activesupport'
49
- require RAILS_ROOT + '/config/environment'
50
- end
51
54
  end
52
55
 
53
56
  class Git < SourceControl
@@ -58,8 +61,8 @@ module MetricFu
58
61
  private
59
62
  def date_range
60
63
  if @start_date
61
- require_rails_env
62
- "--after=#{@start_date.call.strftime('%Y-%m-%d')}"
64
+ date = Chronic.parse(@start_date)
65
+ "--after=#{date.strftime('%Y-%m-%d')}"
63
66
  end
64
67
  end
65
68
 
@@ -73,8 +76,8 @@ module MetricFu
73
76
  private
74
77
  def date_range
75
78
  if @start_date
76
- require_rails_env
77
- "--revision {#{@start_date.call.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
79
+ date = Chronic.parse(@start_date)
80
+ "--revision {#{date.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
78
81
  end
79
82
  end
80
83
 
@@ -0,0 +1,34 @@
1
+ require 'generator'
2
+ module MetricFu
3
+
4
+ class Flay < Generator
5
+
6
+ def self.verify_dependencies!
7
+ `flay --help`
8
+ raise 'sudo gem install flay # if you want the flay tasks' unless $?.success?
9
+ end
10
+
11
+ def emit
12
+ files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
13
+ @output = `flay #{files_to_flay.join(" ")}`
14
+ end
15
+
16
+ def analyze
17
+ @matches = @output.chomp.split("\n\n").map{|m| m.split("\n ") }
18
+ end
19
+
20
+ def to_h
21
+ target = []
22
+ total_score = @matches.shift.first.split('=').last.strip
23
+ @matches.each do |problem|
24
+ reason = problem.shift.strip
25
+ lines_info = problem.map do |full_line|
26
+ name, line = full_line.split(":")
27
+ {:name => name.strip, :line => line.strip}
28
+ end
29
+ target << [:reason => reason, :matches => lines_info]
30
+ end
31
+ {:flay => {:total_score => total_score, :matches => target.flatten}}
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,140 @@
1
+ module MetricFu
2
+
3
+ class Flog < Generator
4
+ attr_reader :pages
5
+
6
+ def self.verify_dependencies!
7
+ `flog --help`
8
+ raise 'sudo gem install flog # if you want the flog tasks' unless $?.success?
9
+ end
10
+
11
+ SCORE_FORMAT = "%0.2f"
12
+ METHOD_LINE_REGEX = /(\d+\.\d+):\s+([A-Za-z:]+#.*)/
13
+ OPERATOR_LINE_REGEX = /\s*(\d+\.\d+):\s(.*)$/
14
+
15
+ def emit
16
+ metric_dir = MetricFu::Flog.metric_directory
17
+ MetricFu.flog[:dirs_to_flog].each do |directory|
18
+ Dir.glob("#{directory}/**/*.rb").each do |filename|
19
+ output_dir = "#{metric_dir}/#{filename.split("/")[0..-2].join("/")}"
20
+ mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir)
21
+ if MetricFu::MD5Tracker.file_changed?(filename, metric_dir)
22
+ `flog -ad #{filename} > #{metric_dir}/#{filename.split('.')[0]}.txt`
23
+ end
24
+ end
25
+ end
26
+ rescue LoadError
27
+ if RUBY_PLATFORM =~ /java/
28
+ puts 'running in jruby - flog tasks not available'
29
+ else
30
+ puts 'sudo gem install flog # if you want the flog tasks'
31
+ end
32
+ end
33
+
34
+ def parse(text)
35
+ summary, methods_summary = text.split "\n\n"
36
+ return unless summary
37
+ score, average = summary.split("\n").map {|line| line[OPERATOR_LINE_REGEX, 1]}
38
+ return nil unless score && methods_summary
39
+ page = Flog::Page.new(score, average)
40
+ methods_summary.each_line do |method_line|
41
+ if match = method_line.match(METHOD_LINE_REGEX)
42
+ page.scanned_methods << ScannedMethod.new(match[2], match[1])
43
+ elsif match = method_line.match(OPERATOR_LINE_REGEX)
44
+ return if page.scanned_methods.empty?
45
+ page.scanned_methods.last.operators << Operator.new(match[1], match[2])
46
+ end
47
+ end
48
+ page
49
+ end
50
+
51
+ def analyze
52
+ @pages = []
53
+ flog_results.each do |path|
54
+ page = parse(open(path, "r") { |f| f.read })
55
+ if page
56
+ page.path = path.sub(metric_directory, "").sub(".txt", ".rb")
57
+ @pages << page
58
+ end
59
+ end
60
+ end
61
+
62
+ def to_h
63
+ number_of_methods = @pages.inject(0) {|count, page| count += page.scanned_methods.size}
64
+ total_flog_score = @pages.inject(0) {|total, page| total += page.score}
65
+ sorted_pages = @pages.sort_by {|page| page.score }.reverse
66
+ {:flog => { :total => total_flog_score,
67
+ :average => average_score(total_flog_score, number_of_methods),
68
+ :pages => sorted_pages.map {|page| page.to_h}}}
69
+ end
70
+
71
+ private
72
+
73
+ def average_score(total_flog_score, number_of_methods)
74
+ return 0 if total_flog_score == 0
75
+ round_to_tenths(total_flog_score/number_of_methods)
76
+ end
77
+
78
+ def flog_results
79
+ Dir.glob("#{metric_directory}/**/*.txt")
80
+ end
81
+
82
+ class Operator
83
+ attr_accessor :score, :operator
84
+
85
+ def initialize(score, operator)
86
+ @score = score.to_f
87
+ @operator = operator
88
+ end
89
+
90
+ def to_h
91
+ {:score => @score, :operator => @operator}
92
+ end
93
+ end
94
+
95
+ class ScannedMethod
96
+ attr_accessor :name, :score, :operators
97
+
98
+ def initialize(name, score, operators = [])
99
+ @name = name
100
+ @score = score.to_f
101
+ @operators = operators
102
+ end
103
+
104
+ def to_h
105
+ {:name => @name,
106
+ :score => @score,
107
+ :operators => @operators.map {|o| o.to_h}}
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ class Flog::Page < MetricFu::Generator
114
+ attr_accessor :path, :score, :scanned_methods, :average_score
115
+
116
+ def initialize(score, average_score, scanned_methods = [])
117
+ @score = score.to_f
118
+ @scanned_methods = scanned_methods
119
+ @average_score = average_score.to_f
120
+ end
121
+
122
+ def filename
123
+ File.basename(path, ".txt")
124
+ end
125
+
126
+ def to_h
127
+ {:score => @score,
128
+ :scanned_methods => @scanned_methods.map {|sm| sm.to_h},
129
+ :highest_score => highest_score,
130
+ :average_score => average_score,
131
+ :path => path}
132
+ end
133
+
134
+ def highest_score
135
+ scanned_methods.inject(0) do |highest, m|
136
+ m.score > highest ? m.score : highest
137
+ end
138
+ end
139
+ end
140
+ end