Class: MetricFu::Flog::Page

Inherits:
Generator show all
Defined in:
lib/generators/flog.rb

Instance Attribute Summary collapse

Attributes inherited from Generator

#report, #template

Instance Method Summary collapse

Methods inherited from Generator

#analyze, class_name, #create_data_dir_if_missing, #create_metric_dir_if_missing, #create_output_dir_if_missing, #emit, generate_report, #generate_report, #metric_directory, metric_directory, #remove_excluded_files, #round_to_tenths, #to_graph, verify_dependencies!

Constructor Details

#initialize(score, average_score, scanned_methods = []) ⇒ Page

Returns a new instance of Page.



143
144
145
146
147
# File 'lib/generators/flog.rb', line 143

def initialize(score, average_score, scanned_methods = [])
  @score = score.to_f
  @scanned_methods = scanned_methods
  @average_score = average_score.to_f
end

Instance Attribute Details

#average_scoreObject

Returns the value of attribute average_score.



141
142
143
# File 'lib/generators/flog.rb', line 141

def average_score
  @average_score
end

#pathObject

Returns the value of attribute path.



141
142
143
# File 'lib/generators/flog.rb', line 141

def path
  @path
end

#scanned_methodsObject

Returns the value of attribute scanned_methods.



141
142
143
# File 'lib/generators/flog.rb', line 141

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



141
142
143
# File 'lib/generators/flog.rb', line 141

def score
  @score
end

Instance Method Details

#filenameObject



149
150
151
# File 'lib/generators/flog.rb', line 149

def filename 
  File.basename(path, ".txt") 
end

#highest_scoreObject



161
162
163
164
165
# File 'lib/generators/flog.rb', line 161

def highest_score
  scanned_methods.inject(0) do |highest, m|
    m.score > highest ? m.score : highest
  end
end

#to_hObject



153
154
155
156
157
158
159
# File 'lib/generators/flog.rb', line 153

def to_h
  {:score => @score, 
   :scanned_methods => @scanned_methods.map {|sm| sm.to_h},
   :highest_score => highest_score,
   :average_score => average_score,
   :path => path}
end