Class: AocCli::Database::Attempt
- Inherits:
-
Object
- Object
- AocCli::Database::Attempt
- Defined in:
- lib/aoc_cli/database.rb
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #cols ⇒ Object
- #correct ⇒ Object
- #count_attempts ⇒ Object
- #data ⇒ Object
- #duplicate?(ans:) ⇒ Boolean
- #incorrect(low:, high:) ⇒ Object
-
#initialize(attempt:) ⇒ Attempt
constructor
A new instance of Attempt.
- #parse_hint(low:, high:) ⇒ Object
- #where ⇒ Object
Constructor Details
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
40 41 42 |
# File 'lib/aoc_cli/database.rb', line 40 def attempt @attempt end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
40 41 42 |
# File 'lib/aoc_cli/database.rb', line 40 def db @db end |
Instance Method Details
#cols ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
46 47 48 49 |
# File 'lib/aoc_cli/database.rb', line 46 def correct db.insert(t:"attempts", val:data << 1 << 0 << 0) self end |
#count_attempts ⇒ Object
79 80 81 |
# File 'lib/aoc_cli/database.rb', line 79 def count_attempts db.select(t:"attempts", where:where).count end |
#data ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/aoc_cli/database.rb', line 62 def data [ "'#{Time.now}'", "'#{attempt.year}'", "'#{attempt.day}'", "'#{attempt.part}'", "'#{attempt.answer}'" ] end |
#duplicate?(ans:) ⇒ Boolean
55 56 57 58 |
# 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:) ⇒ Object
50 51 52 53 54 |
# 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:) ⇒ Object
59 60 61 |
# File 'lib/aoc_cli/database.rb', line 59 def parse_hint(low:, high:) [ low ? 1 : 0, high ? 1 : 0 ] end |
#where ⇒ Object
82 83 84 85 86 |
# File 'lib/aoc_cli/database.rb', line 82 def where { year:attempt.year, day:attempt.day, part:attempt.part } end |