Class: Hbtrack::CompletionRateSF
- Inherits:
-
Object
- Object
- Hbtrack::CompletionRateSF
- Defined in:
- lib/hbtrack/stat_formatter.rb
Instance Method Summary collapse
-
#format(hash) ⇒ String
Format in terms of the completion rate of the habit.
-
#to_percentage(hash) ⇒ Hash
Convert the value in the hash into percentage.
Instance Method Details
#format(hash) ⇒ String
Format in terms of the completion rate of the habit.
37 38 39 40 |
# File 'lib/hbtrack/stat_formatter.rb', line 37 def format(hash) percentage = to_percentage(hash)[:done] sprintf("Completion rate: %.2f%%", percentage) end |
#to_percentage(hash) ⇒ Hash
Convert the value in the hash into percentage
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hbtrack/stat_formatter.rb', line 47 def to_percentage(hash) total = hash[:done] + hash[:undone] done_p = 0 undone_p = 0 unless total.zero? done_p = hash[:done] / total.to_f * 100 undone_p = hash[:undone] / total.to_f * 100 end { done: done_p, undone: undone_p } end |