Class: AocCli::Tables::Table
- Inherits:
-
Object
- Object
- AocCli::Tables::Table
- Defined in:
- lib/aoc_cli/tables.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#where ⇒ Object
readonly
Returns the value of attribute where.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #border ⇒ Object
- #data ⇒ Object
-
#initialize(u: Metafile.get(:user), y: Metafile.get(:year)) ⇒ Table
constructor
A new instance of Table.
- #make ⇒ Object
- #print ⇒ Object
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
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
5 6 7 |
# File 'lib/aoc_cli/tables.rb', line 5 def cols @cols end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
5 6 7 |
# File 'lib/aoc_cli/tables.rb', line 5 def table @table end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/aoc_cli/tables.rb', line 5 def user @user end |
#where ⇒ Object (readonly)
Returns the value of attribute where.
5 6 7 |
# File 'lib/aoc_cli/tables.rb', line 5 def where @where end |
#year ⇒ Object (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
#border ⇒ Object
10 11 12 |
# File 'lib/aoc_cli/tables.rb', line 10 def border Prefs.bool(key:"unicode_tables") ? :unicode : :ascii end |
#data ⇒ Object
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 |
#make ⇒ Object
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 |
#print ⇒ Object
18 19 20 |
# File 'lib/aoc_cli/tables.rb', line 18 def print puts rows.count > 0 ? make : end |