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, #round_to_tenths, #to_graph, verify_dependencies!

Constructor Details

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

Returns a new instance of Page.



116
117
118
119
120
# File 'lib/generators/flog.rb', line 116

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.



114
115
116
# File 'lib/generators/flog.rb', line 114

def average_score
  @average_score
end

#pathObject

Returns the value of attribute path.



114
115
116
# File 'lib/generators/flog.rb', line 114

def path
  @path
end

#scanned_methodsObject

Returns the value of attribute scanned_methods.



114
115
116
# File 'lib/generators/flog.rb', line 114

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



114
115
116
# File 'lib/generators/flog.rb', line 114

def score
  @score
end

Instance Method Details

#filenameObject



122
123
124
# File 'lib/generators/flog.rb', line 122

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

#highest_scoreObject



134
135
136
137
138
# File 'lib/generators/flog.rb', line 134

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

#to_hObject



126
127
128
129
130
131
132
# File 'lib/generators/flog.rb', line 126

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