Class: AocCli::Year::Requests::Stats

Inherits:
Request show all
Defined in:
lib/aoc_cli/year.rb

Instance Attribute Summary

Attributes inherited from Request

#data

Attributes inherited from Meta

#paths, #user, #year

Instance Method Summary collapse

Methods inherited from Request

#initialize

Methods inherited from Meta

#initialize, #write

Constructor Details

This class inherits a constructor from AocCli::Year::Requests::Request

Instance Method Details

#pageObject



74
75
76
# File 'lib/aoc_cli/year.rb', line 74

def page
  :Stats
end

#parse(raw:) ⇒ Object



77
78
79
80
# File 'lib/aoc_cli/year.rb', line 77

def parse(raw:)
  /You haven't collected/.match?(raw.to_s) ?
    raw : raw.drop(raw.index{|l| l =~ /^.*Part 1/}) 
end

#starsObject



81
82
83
84
85
86
87
# File 'lib/aoc_cli/year.rb', line 81

def stars
  data.map{|l| l.scan(/^\s+\d+/)&.first}
    .reject{|s| s == nil}
    .map{|s| [s.to_i, data
    .grep(/^.*#{s}.*(\-.*){3}$/)
    .count == 0 ? 2 : 1]}.to_h
end

#total_starsObject



88
89
90
# File 'lib/aoc_cli/year.rb', line 88

def total_stars
  stars.values.reduce(:+).to_i || 0
end