class AocCli::Database::Attempt
Attributes
attempt[R]
db[R]
Public Class Methods
new(attempt:)
click to toggle source
# File lib/aoc_cli/database.rb, line 41 def initialize(attempt:) @attempt = attempt @db = Query.new(path:Paths::Database.cfg(attempt.user)) .table(t:"attempts", cols:cols) end
Public Instance Methods
cols()
click to toggle source
# File lib/aoc_cli/database.rb, line 69 def cols { time: :TEXT, year: :INT, day: :INT, part: :INT, answer: :TEXT, correct: :INT, low: :INT, high: :INT } end
correct()
click to toggle source
# File lib/aoc_cli/database.rb, line 46 def correct db.insert(t:"attempts", val:data << 1 << 0 << 0) self end
count_attempts()
click to toggle source
# File lib/aoc_cli/database.rb, line 79 def count_attempts db.select(t:"attempts", where:where).count end
data()
click to toggle source
# File lib/aoc_cli/database.rb, line 62 def data [ "'#{Time.now}'", "'#{attempt.year}'", "'#{attempt.day}'", "'#{attempt.part}'", "'#{attempt.answer}'" ] end
duplicate?(ans:)
click to toggle source
# File lib/aoc_cli/database.rb, line 55 def duplicate?(ans:) db.select(t:"attempts", where:where.merge({answer:"'#{ans}'"})).count > 0 end
incorrect(low:, high:)
click to toggle source
# File lib/aoc_cli/database.rb, line 50 def incorrect(low:, high:) db.insert(t:"attempts", val:data << 0 << parse_hint(low:low, high:high)) self end
parse_hint(low:, high:)
click to toggle source
# File lib/aoc_cli/database.rb, line 59 def parse_hint(low:, high:) [ low ? 1 : 0, high ? 1 : 0 ] end
where()
click to toggle source
# File lib/aoc_cli/database.rb, line 82 def where { year:attempt.year, day:attempt.day, part:attempt.part } end