Class: AocCli::Stats

Inherits:
Kangaru::Model
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/aoc_cli/models/stats.rb

Instance Method Summary collapse

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

Returns:

  • (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

#presenterObject



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

#totalObject



19
20
21
# File 'lib/aoc_cli/models/stats.rb', line 19

def total
  1.upto(25).map { |day| progress(day) }.sum
end