Class: AocCli::Year::Requests::Stats
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
Instance Method Details
#page ⇒ Object
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
|
#stars ⇒ Object
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_stars ⇒ Object
88
89
90
|
# File 'lib/aoc_cli/year.rb', line 88
def total_stars
stars.values.reduce(:+).to_i || 0
end
|