Class: AocCli::Solve::Attempt

Inherits:
Object
  • Object
show all
Defined in:
lib/aoc_cli/solve.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u: Metafile.get(:user), y: Metafile.get(:year), d: Metafile.get(:day), p: Metafile.get(:part), a:) ⇒ Attempt

Returns a new instance of Attempt.



8
9
10
11
12
13
14
15
16
17
# File 'lib/aoc_cli/solve.rb', line 8

def initialize(u:Metafile.get(:user),
         y:Metafile.get(:year),
         d:Metafile.get(:day),
         p:Metafile.get(:part), a:)
  @user   = Validate.user(u)
  @year   = Validate.year(y)
  @day    = Validate.day(d)
  @part   = Validate.part(p)
  @answer = Validate.ans(attempt:self, ans:a)
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



7
8
9
# File 'lib/aoc_cli/solve.rb', line 7

def answer
  @answer
end

#dayObject (readonly)

Returns the value of attribute day.



7
8
9
# File 'lib/aoc_cli/solve.rb', line 7

def day
  @day
end

#partObject (readonly)

Returns the value of attribute part.



7
8
9
# File 'lib/aoc_cli/solve.rb', line 7

def part
  @part
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/aoc_cli/solve.rb', line 7

def user
  @user
end

#yearObject (readonly)

Returns the value of attribute year.



7
8
9
# File 'lib/aoc_cli/solve.rb', line 7

def year
  @year
end

Instance Method Details

#checkObject



25
26
27
28
29
30
31
# File 'lib/aoc_cli/solve.rb', line 25

def check
  case raw
  when /#{CORRECT}/   then :Correct
  when /#{INCORRECT}/ then :Incorrect
  when /#{WAIT}/      then :Wait
  end
end

#exists?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/aoc_cli/solve.rb', line 18

def exists?
  Database::Attempt.new(attempt:self)
end

#rawObject



21
22
23
24
# File 'lib/aoc_cli/solve.rb', line 21

def raw
  @raw ||= Tools::Post.new(u:user, y:year, d:day, 
     data:{level:part, answer:answer}).plain
end

#respondObject



32
33
34
35
36
37
# File 'lib/aoc_cli/solve.rb', line 32

def respond
  Respond.const_get(check)
    .new(attempt:self)
    .respond
    .react
end