Module: CompletenessFu::ActiveModelAdditions::InstanceMethods
- Defined in:
- lib/completeness-fu/active_model_additions.rb
Instance Method Summary collapse
-
#completeness_grade ⇒ Object
returns a basic ‘grading’ based on percent_complete, defaults are :high, :medium, :low, and :poor.
-
#completeness_score ⇒ Object
returns the absolute complete score.
-
#failed_checks ⇒ Object
returns an array of hashes with the translated name, description + weighting.
-
#passed_checks ⇒ Object
returns an array of hashes with the translated name, description + weighting.
-
#percent_complete ⇒ Object
returns the percentage of completeness (relative score).
Instance Method Details
#completeness_grade ⇒ Object
returns a basic ‘grading’ based on percent_complete, defaults are :high, :medium, :low, and :poor
70 71 72 73 74 75 |
# File 'lib/completeness-fu/active_model_additions.rb', line 70 def completeness_grade CompletenessFu.default_gradings.each do |grading| return grading.first if grading.last.include?(self.percent_complete.round) end raise CompletenessFuError, "grade could not be determined with percent complete #{self.percent_complete.round}" end |
#completeness_score ⇒ Object
returns the absolute complete score
58 59 60 61 62 |
# File 'lib/completeness-fu/active_model_additions.rb', line 58 def completeness_score sum_score = 0 passed_checks.each { |check| sum_score += check[:weighting] } sum_score end |
#failed_checks ⇒ Object
returns an array of hashes with the translated name, description + weighting
48 49 50 |
# File 'lib/completeness-fu/active_model_additions.rb', line 48 def failed_checks all_checks_which_pass(false) end |
#passed_checks ⇒ Object
returns an array of hashes with the translated name, description + weighting
53 54 55 |
# File 'lib/completeness-fu/active_model_additions.rb', line 53 def passed_checks all_checks_which_pass end |
#percent_complete ⇒ Object
returns the percentage of completeness (relative score)
65 66 67 |
# File 'lib/completeness-fu/active_model_additions.rb', line 65 def percent_complete self.completeness_score.to_f / self.class.max_completeness_score.to_f * 100 end |