Class: ColorfulTables::Table
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :border_color => :light_blue }
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(data, options = {}) ⇒ Table
constructor
A new instance of Table.
- #page(n) ⇒ Object
- #paginate ⇒ Object
Constructor Details
#initialize(data, options = {}) ⇒ Table
Returns a new instance of Table.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/colorful_tables/table.rb', line 15 def initialize(data, = {}) #raise RuntimeError, "data must be an array of columns" unless is_an_array_of_columns?(data) @data = data @options = .reverse_merge!(DEFAULT_OPTIONS) @border_chars ||= calculate_border_chars @columns_width ||= calculate_columns_width @columns_options ||= @terminal_height ||= ColorfulTables.detect_terminal_size[1] @transposed_data ||= self.data.map(&:data).transpose end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/colorful_tables/table.rb', line 13 def data @data end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/colorful_tables/table.rb', line 13 def @options end |
Instance Method Details
#page(n) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/colorful_tables/table.rb', line 26 def page(n) return nil if n >= total_pages page_output = @transposed_data[page_ranges[n]].inject("\r" + header) do |output, row| output += format(row) end page_output += separator page_output end |
#paginate ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/colorful_tables/table.rb', line 35 def paginate total_pages.times do |n| puts page(n) print "-- Press ENTER --" STDIN.getc end end |