class AocCli::Database::Stats::Init

Attributes

day[R]
db[R]
now[R]
part[R]
user[R]
year[R]

Public Class Methods

new(u:Metafile.get(:user), y:Metafile.get(:year), d:Metafile.get(:day), p:Metafile.get(:part)) click to toggle source
# File lib/aoc_cli/database.rb, line 91
def initialize(u:Metafile.get(:user),
                           y:Metafile.get(:year),
                           d:Metafile.get(:day),
                           p:Metafile.get(:part))
        @user = Validate.user(u)
        @year = Validate.year(y)
        @day  = Validate.day(d)
        @part = p
        @now  = Time.now
        @db   = Query.new(path:Paths::Database.cfg(user))
                         .table(t:"stats", cols:cols)
end

Public Instance Methods

cols() click to toggle source
# File lib/aoc_cli/database.rb, line 103
def cols
        { year: :INT, 
          day: :INT, 
          part: :INT, 
          dl_time: :TEXT,
          end_time: :TEXT,
          elapsed: :TEXT,
          attempts: :INT,
          correct: :INT }
end
data() click to toggle source
# File lib/aoc_cli/database.rb, line 116
def data
        [ "'#{year}'",
          "'#{day}'",
          "'#{part}'",
          "'#{now}'",
          "NULL",
          "NULL",
          "'0'",
          "'0'" ]
end
init() click to toggle source
# File lib/aoc_cli/database.rb, line 113
def init
        db.insert(t:"stats", val:data)
end