VERSION | = | '1.4.4' |
VERSION | = | '1.4.4' |
headings | [R] | |
headings | [R] | |
title | [R] | |
title | [R] |
Generates a ASCII table with the given options.
# File lib/terminal-table/table.rb, line 11 11: def initialize options = {}, &block 12: @column_widths = [] 13: self.style = options.fetch :style, {} 14: self.title = options.fetch :title, nil 15: self.headings = options.fetch :headings, [] 16: self.rows = options.fetch :rows, [] 17: yield_or_eval(&block) if block 18: end
Generates a ASCII table with the given options.
# File lib/terminal-table/table.rb, line 11 11: def initialize options = {}, &block 12: @column_widths = [] 13: self.style = options.fetch :style, {} 14: self.title = options.fetch :title, nil 15: self.headings = options.fetch :headings, [] 16: self.rows = options.fetch :rows, [] 17: yield_or_eval(&block) if block 18: end
Check if other is equal to self. other is considered equal if it contains the same headings and rows.
# File lib/terminal-table/table.rb, line 154 154: def == other 155: if other.respond_to? :render and other.respond_to? :rows 156: self.headings == other.headings and self.rows == other.rows 157: end 158: end
Check if other is equal to self. other is considered equal if it contains the same headings and rows.
# File lib/terminal-table/table.rb, line 154 154: def == other 155: if other.respond_to? :render and other.respond_to? :rows 156: self.headings == other.headings and self.rows == other.rows 157: end 158: end
Add a row.
# File lib/terminal-table/table.rb, line 34 34: def add_row array 35: row = array == :separator ? Separator.new(self) : Row.new(self, array) 36: @rows << row 37: recalc_column_widths row 38: end
Add a row.
# File lib/terminal-table/table.rb, line 34 34: def add_row array 35: row = array == :separator ? Separator.new(self) : Row.new(self, array) 36: @rows << row 37: recalc_column_widths row 38: end
Add a separator.
# File lib/terminal-table/table.rb, line 44 44: def add_separator 45: self << :separator 46: end
Add a separator.
# File lib/terminal-table/table.rb, line 44 44: def add_separator 45: self << :separator 46: end
# File lib/terminal-table/table.rb, line 52 52: def cell_padding 53: style.padding_left + style.padding_right 54: end
# File lib/terminal-table/table.rb, line 52 52: def cell_padding 53: style.padding_left + style.padding_right 54: end
# File lib/terminal-table/table.rb, line 48 48: def cell_spacing 49: cell_padding + style.border_y.length 50: end
# File lib/terminal-table/table.rb, line 48 48: def cell_spacing 49: cell_padding + style.border_y.length 50: end
Set the headings
# File lib/terminal-table/table.rb, line 99 99: def headings= array 100: @headings = Row.new(self, array) 101: recalc_column_widths @headings 102: end
Set the headings
# File lib/terminal-table/table.rb, line 99 99: def headings= array 100: @headings = Row.new(self, array) 101: recalc_column_widths @headings 102: end
Render the table.
# File lib/terminal-table/table.rb, line 107 107: def render 108: separator = Separator.new(self) 109: buffer = [separator] 110: unless @title.nil? 111: opts = {:value => @title, :alignment => :center, :colspan => number_of_columns} 112: buffer << Row.new(self, [opts]) 113: buffer << separator 114: end 115: unless @headings.cells.empty? 116: buffer << @headings 117: buffer << separator 118: end 119: buffer += @rows 120: buffer << separator 121: buffer.map { |r| r.render }.join("\n") 122: end
Render the table.
# File lib/terminal-table/table.rb, line 107 107: def render 108: separator = Separator.new(self) 109: buffer = [separator] 110: unless @title.nil? 111: opts = {:value => @title, :alignment => :center, :colspan => number_of_columns} 112: buffer << Row.new(self, [opts]) 113: buffer << separator 114: end 115: unless @headings.cells.empty? 116: buffer << @headings 117: buffer << separator 118: end 119: buffer += @rows 120: buffer << separator 121: buffer.map { |r| r.render }.join("\n") 122: end
# File lib/terminal-table/table.rb, line 132 132: def rows= array 133: @rows = [] 134: array.each { |arr| self << arr } 135: end
# File lib/terminal-table/table.rb, line 132 132: def rows= array 133: @rows = [] 134: array.each { |arr| self << arr } 135: end
# File lib/terminal-table/table.rb, line 137 137: def style=(options) 138: style.apply options 139: end
# File lib/terminal-table/table.rb, line 137 137: def style=(options) 138: style.apply options 139: end
# File lib/terminal-table/table.rb, line 145 145: def title=(title) 146: @title = title 147: recalc_column_widths Row.new(self, [title]) 148: end