Class: AocCli::Tables::Attempts

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

Instance Attribute Summary collapse

Attributes inherited from Table

#cols, #table, #user, #where, #year

Instance Method Summary collapse

Methods inherited from Table

#border, #data, #make, #print

Constructor Details

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

Returns a new instance of Attempts.



34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



33
34
35
# File 'lib/aoc_cli/tables.rb', line 33

def day
  @day
end

#partObject (readonly)

Returns the value of attribute part.



33
34
35
# File 'lib/aoc_cli/tables.rb', line 33

def part
  @part
end

Instance Method Details

#headingsObject



48
49
50
# File 'lib/aoc_cli/tables.rb', line 48

def headings
	["Answer", "Time", "Hint"]
end

#nil_messageObject



67
68
69
# File 'lib/aoc_cli/tables.rb', line 67

def nil_message
	"You have not attempted part #{part} yet!"
end

#parse_ans(row) ⇒ Object



56
57
58
# 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) ⇒ Object



63
64
65
66
# File 'lib/aoc_cli/tables.rb', line 63

def parse_hint(row)
	row[3] == 1 ? "low" : 
		row[2] == 1 ? "high" : "-"
end

#parse_time(row) ⇒ Object



59
60
61
62
# 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

#rowsObject



51
52
53
54
55
# 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

#titleObject



45
46
47
# File 'lib/aoc_cli/tables.rb', line 45

def title
	"#{year} - Day #{day}:#{part}".bold
end