Class: ValidationErrorReporter::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/validation_error_reporter/profiler.rb

Instance Method Summary collapse

Constructor Details

#initializeProfiler

Returns a new instance of Profiler.



4
5
6
# File 'lib/validation_error_reporter/profiler.rb', line 4

def initialize
  @profile = Hash.new { |h, k| h[k] = { count: 0, total: 0 } }
end

Instance Method Details

#profile(errors) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/validation_error_reporter/profiler.rb', line 8

def profile(errors)
  errors.each do |error|
    @profile[error.model_name][:count] += 1
    @profile[error.model_name][:total] = error.model_total_count
  end

  @profile.each_value do |hash|
    hash[:rate] = hash[:count].to_f / hash[:total].to_f * 100
  end

  @profile
end