Class: AocCli::Database::Stats::Init

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

Direct Known Subclasses

Complete

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Init.



91
92
93
94
95
96
97
98
99
100
101
102
# 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

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def day
  @day
end

#dbObject (readonly)

Returns the value of attribute db.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def db
  @db
end

#nowObject (readonly)

Returns the value of attribute now.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def now
  @now
end

#partObject (readonly)

Returns the value of attribute part.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def part
  @part
end

#userObject (readonly)

Returns the value of attribute user.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def user
  @user
end

#yearObject (readonly)

Returns the value of attribute year.



90
91
92
# File 'lib/aoc_cli/database.rb', line 90

def year
  @year
end

Instance Method Details

#colsObject



103
104
105
106
107
108
109
110
111
112
# 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

#dataObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/aoc_cli/database.rb', line 116

def data
	[ "'#{year}'",
	  "'#{day}'",
	  "'#{part}'",
	  "'#{now}'",
	  "NULL",
	  "NULL",
	  "'0'",
	  "'0'" ]
end

#initObject



113
114
115
# File 'lib/aoc_cli/database.rb', line 113

def init
	db.insert(t:"stats", val:data)
end