class AocCli::Database::Calendar::Init
Attributes
db[R]
stars[R]
user[R]
year[R]
Public Class Methods
new(u:Metafile.get(:user), y:Metafile.get(:year), stars:)
click to toggle source
# File lib/aoc_cli/database.rb, line 168 def initialize(u:Metafile.get(:user), y:Metafile.get(:year), stars:) @user = Validate.user(u) @year = Validate.year(y) @stars = stars @db = Query .new(path:Paths::Database.cfg(user)) .table(t:"calendar", cols:cols) end
Public Instance Methods
cols()
click to toggle source
# File lib/aoc_cli/database.rb, line 178 def cols { year: :INT, day: :INT, stars: :TEXT } end
day_data(day)
click to toggle source
# File lib/aoc_cli/database.rb, line 186 def day_data(day) ["'#{year}'", "'#{day}'", "'#{n_stars(day)}'"] end
insert()
click to toggle source
# File lib/aoc_cli/database.rb, line 192 def insert unless table_exist? 1.upto(25){|day| db.insert(t:"calendar", val:day_data(day))} end end
n_stars(day)
click to toggle source
# File lib/aoc_cli/database.rb, line 183 def n_stars(day) stars.keys.include?(day) ? stars[day] : 0 end
table_exist?()
click to toggle source
# File lib/aoc_cli/database.rb, line 189 def table_exist? db.select(t:"calendar", where:{year:"'#{year}'"}).count > 0 end