Class: AocCli::Tables::Table

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

Direct Known Subclasses

Attempts, Calendar, Stats::Year

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u: Metafile.get(:user), y: Metafile.get(:year)) ⇒ Table



6
7
8
9
# File 'lib/aoc_cli/tables.rb', line 6

def initialize(u:Metafile.get(:user), y:Metafile.get(:year))
  @user = Validate.user(u)
  @year = Validate.year(y)
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



5
6
7
# File 'lib/aoc_cli/tables.rb', line 5

def cols
  @cols
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/aoc_cli/tables.rb', line 5

def table
  @table
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/aoc_cli/tables.rb', line 5

def user
  @user
end

#whereObject (readonly)

Returns the value of attribute where.



5
6
7
# File 'lib/aoc_cli/tables.rb', line 5

def where
  @where
end

#yearObject (readonly)

Returns the value of attribute year.



5
6
7
# File 'lib/aoc_cli/tables.rb', line 5

def year
  @year
end

Instance Method Details

#borderObject



10
11
12
# File 'lib/aoc_cli/tables.rb', line 10

def border
  Prefs.bool(key:"unicode_tables") ? :unicode : :ascii
end

#dataObject



13
14
15
16
17
# File 'lib/aoc_cli/tables.rb', line 13

def data
  Database::Query
    .new(path:Paths::Database.cfg(user))
    .select(t:table, cols:cols, where:where)
end

#makeObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/aoc_cli/tables.rb', line 21

def make
  tab = Terminal::Table.new(
    :headings  => headings,
    :rows      => rows,
    :title     => title)
  tab.style = {
    :border    => border, 
    :alignment => :center}
  tab
end


18
19
20
# File 'lib/aoc_cli/tables.rb', line 18

def print
  puts rows.count > 0 ? make : nil_message
end