Module: CompletenessFu::ActiveRecordAdditions::InstanceMethods
- Defined in:
- lib/completeness-fu/active_record_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
77 78 79 80 81 |
# File 'lib/completeness-fu/active_record_additions.rb', line 77 def completeness_grade CompletenessFu.default_grading.each do |grading| return grading.first if grading.last.include?(self.percent_complete) end end |
#completeness_score ⇒ Object
returns the absolute complete score
65 66 67 68 69 |
# File 'lib/completeness-fu/active_record_additions.rb', line 65 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
43 44 45 46 47 48 |
# File 'lib/completeness-fu/active_record_additions.rb', line 43 def failed_checks self.completeness_checks.inject([]) do |failures, check| failures << translate_check_details(check) if not check[:check].call(self) failures end end |
#passed_checks ⇒ Object
returns an array of hashes with the translated name, description + weighting
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/completeness-fu/active_record_additions.rb', line 51 def passed_checks self.completeness_checks.inject([]) do |passed, check| case check[:check] when Proc passed << translate_check_details(check) if check[:check].call(self) when Symbol passed << translate_check_details(check) if self.send check[:check] end passed end end |
#percent_complete ⇒ Object
returns the percentage of completeness (relative score)
72 73 74 |
# File 'lib/completeness-fu/active_record_additions.rb', line 72 def percent_complete self.completeness_score.to_f / self.class.max_completeness_score.to_f * 100 end |