Class: AocCli::Database::Calendar::Part

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u: Metafile.get(:user), y: Metafile.get(:year), d: Metafile.get(:day)) ⇒ Part

Returns a new instance of Part.



202
203
204
205
206
207
208
209
# File 'lib/aoc_cli/database.rb', line 202

def initialize(u:Metafile.get(:user),
			   y:Metafile.get(:year),
			   d:Metafile.get(:day))
	@user = Validate.user(u)
	@year = Validate.year(y)
	@day  = Validate.day(d)
	@db   = Query.new(path:Paths::Database.cfg(user))
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



201
202
203
# File 'lib/aoc_cli/database.rb', line 201

def day
  @day
end

#dbObject (readonly)

Returns the value of attribute db.



201
202
203
# File 'lib/aoc_cli/database.rb', line 201

def db
  @db
end

#userObject (readonly)

Returns the value of attribute user.



201
202
203
# File 'lib/aoc_cli/database.rb', line 201

def user
  @user
end

#yearObject (readonly)

Returns the value of attribute year.



201
202
203
# File 'lib/aoc_cli/database.rb', line 201

def year
  @year
end

Instance Method Details

#getObject



210
211
212
213
# File 'lib/aoc_cli/database.rb', line 210

def get
	db.select(t:"calendar", cols:"stars", where:where)
		.flatten.first.to_i + 1
end

#incrementObject



214
215
216
# File 'lib/aoc_cli/database.rb', line 214

def increment
	db.update(t:"calendar", val:{stars:get}, where:where)
end

#whereObject



217
218
219
220
# File 'lib/aoc_cli/database.rb', line 217

def where
	{ year:"'#{year}'",
	   day:"'#{day}'" }
end