Class: Taql::Table
- Inherits:
-
Object
- Object
- Taql::Table
- Defined in:
- lib/taql/table.rb
Constant Summary collapse
- DASH =
"-".freeze
- PLUS =
"+".freeze
- SPACE =
" ".freeze
- VERTICAL_BAR =
"|".freeze
Instance Attribute Summary collapse
-
#markdown ⇒ Object
Returns the value of attribute markdown.
Instance Method Summary collapse
- #body ⇒ Object
- #columns ⇒ Object
- #headers ⇒ Object
-
#initialize(entries, markdown: false) ⇒ Table
constructor
A new instance of Table.
- #print ⇒ Object (also: #to_s)
- #rows ⇒ Object
Constructor Details
#initialize(entries, markdown: false) ⇒ Table
Returns a new instance of Table.
10 11 12 13 |
# File 'lib/taql/table.rb', line 10 def initialize(entries, markdown: false) @entries = entries.map { |entry| entry.transform_values(&:to_s) } @markdown = markdown end |
Instance Attribute Details
#markdown ⇒ Object
Returns the value of attribute markdown.
8 9 10 |
# File 'lib/taql/table.rb', line 8 def markdown @markdown end |
Instance Method Details
#body ⇒ Object
15 16 17 |
# File 'lib/taql/table.rb', line 15 def body entries.map(&:values) end |
#columns ⇒ Object
19 20 21 22 23 |
# File 'lib/taql/table.rb', line 19 def columns headers.map do |header| [header, *entries.map { |entry| entry[header] }] end end |
#headers ⇒ Object
25 26 27 |
# File 'lib/taql/table.rb', line 25 def headers entries.map(&:keys).uniq.flatten end |
#print ⇒ Object Also known as: to_s
29 30 31 |
# File 'lib/taql/table.rb', line 29 def print output if entries.any? end |
#rows ⇒ Object
33 34 35 |
# File 'lib/taql/table.rb', line 33 def rows [headers, *body] end |