class AocCli::Tables::Attempts
Attributes
day[R]
part[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
Calls superclass method
AocCli::Tables::Table::new
# File lib/aoc_cli/tables.rb, line 34 def initialize(u:Metafile.get(:user), y:Metafile.get(:year), d:Metafile.get(:day), p:Metafile.get(:part)) super(u:u, y:y) @day = Validate.day(d) @part = Validate.part(p) @table = :attempts @cols = "time, answer, high, low, correct" @where = {year:year, day:day, part:part} end
Public Instance Methods
headings()
click to toggle source
# File lib/aoc_cli/tables.rb, line 48 def headings ["Answer", "Time", "Hint"] end
nil_message()
click to toggle source
# File lib/aoc_cli/tables.rb, line 67 def nil_message "You have not attempted part #{part} yet!" end
parse_ans(row)
click to toggle source
# File lib/aoc_cli/tables.rb, line 56 def parse_ans(row) row[4] == 1 ? row[1].to_s.green : row[1].to_s.red end
parse_hint(row)
click to toggle source
# File lib/aoc_cli/tables.rb, line 63 def parse_hint(row) row[3] == 1 ? "low" : row[2] == 1 ? "high" : "-" end
parse_time(row)
click to toggle source
# File lib/aoc_cli/tables.rb, line 59 def parse_time(row) DateTime.strptime(row[0], "%Y-%m-%d %H:%M:%S %Z") .strftime("%H:%M - %d/%m/%y") end
rows()
click to toggle source
# File lib/aoc_cli/tables.rb, line 51 def rows @rows ||= data.map do |d| [parse_ans(d), parse_time(d), parse_hint(d)] end end
title()
click to toggle source
# File lib/aoc_cli/tables.rb, line 45 def title "#{year} - Day #{day}:#{part}".bold end