Class: AocCli::Stats
- Inherits:
-
Kangaru::Model
- Object
- Kangaru::Model
- AocCli::Stats
- Extended by:
- Forwardable
- Defined in:
- lib/aoc_cli/models/stats.rb
Instance Method Summary collapse
- #advance_progress!(day) ⇒ Object
- #complete?(day) ⇒ Boolean
- #current_level(day) ⇒ Object
- #presenter ⇒ Object
- #progress(day) ⇒ Object
- #total ⇒ Object
Instance Method Details
#advance_progress!(day) ⇒ Object
37 38 39 40 41 |
# File 'lib/aoc_cli/models/stats.rb', line 37 def advance_progress!(day) raise "already complete" if complete?(day) update("day_#{day}": current_level(day)) end |
#complete?(day) ⇒ Boolean
33 34 35 |
# File 'lib/aoc_cli/models/stats.rb', line 33 def complete?(day) progress(day) == 2 end |
#current_level(day) ⇒ Object
27 28 29 30 31 |
# File 'lib/aoc_cli/models/stats.rb', line 27 def current_level(day) return if complete?(day) progress(day) + 1 end |
#presenter ⇒ Object
15 16 17 |
# File 'lib/aoc_cli/models/stats.rb', line 15 def presenter @presenter ||= Presenters::StatsPresenter.new(self) end |
#progress(day) ⇒ Object
23 24 25 |
# File 'lib/aoc_cli/models/stats.rb', line 23 def progress(day) self[:"day_#{day}"] || raise("invalid day") end |
#total ⇒ Object
19 20 21 |
# File 'lib/aoc_cli/models/stats.rb', line 19 def total 1.upto(25).map { |day| progress(day) }.sum end |