Class: AocCli::Database::Calendar::Init
- Inherits:
-
Object
- Object
- AocCli::Database::Calendar::Init
- Defined in:
- lib/aoc_cli/database.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#stars ⇒ Object
readonly
Returns the value of attribute stars.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #cols ⇒ Object
- #day_data(day) ⇒ Object
-
#initialize(u: Metafile.get(:user), y: Metafile.get(:year), stars:) ⇒ Init
constructor
A new instance of Init.
- #insert ⇒ Object
- #n_stars(day) ⇒ Object
- #table_exist? ⇒ Boolean
Constructor Details
#initialize(u: Metafile.get(:user), y: Metafile.get(:year), stars:) ⇒ Init
Returns a new instance of Init.
168 169 170 171 172 173 174 175 176 177 |
# 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 |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
167 168 169 |
# File 'lib/aoc_cli/database.rb', line 167 def db @db end |
#stars ⇒ Object (readonly)
Returns the value of attribute stars.
167 168 169 |
# File 'lib/aoc_cli/database.rb', line 167 def stars @stars end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
167 168 169 |
# File 'lib/aoc_cli/database.rb', line 167 def user @user end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
167 168 169 |
# File 'lib/aoc_cli/database.rb', line 167 def year @year end |
Instance Method Details
#cols ⇒ Object
178 179 180 181 182 |
# File 'lib/aoc_cli/database.rb', line 178 def cols { year: :INT, day: :INT, stars: :TEXT } end |
#day_data(day) ⇒ Object
186 187 188 |
# File 'lib/aoc_cli/database.rb', line 186 def day_data(day) ["'#{year}'", "'#{day}'", "'#{n_stars(day)}'"] end |
#insert ⇒ Object
192 193 194 195 196 197 198 |
# 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) ⇒ Object
183 184 185 |
# File 'lib/aoc_cli/database.rb', line 183 def n_stars(day) stars.keys.include?(day) ? stars[day] : 0 end |
#table_exist? ⇒ Boolean
189 190 191 |
# File 'lib/aoc_cli/database.rb', line 189 def table_exist? db.select(t:"calendar", where:{year:"'#{year}'"}).count > 0 end |