Class: PrettyTable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [], headers = []) ⇒ PrettyTable

Returns a new instance of PrettyTable.



4
5
6
7
# File 'lib/pretty_table.rb', line 4

def initialize(data = [], headers = [])
  @data    = data
  @headers = headers
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



2
3
4
# File 'lib/pretty_table.rb', line 2

def data
  @data
end

#headersObject (readonly)

Returns the value of attribute headers.



2
3
4
# File 'lib/pretty_table.rb', line 2

def headers
  @headers
end

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pretty_table.rb', line 9

def to_s
  string = ''
  string << header_cells.join(' | ')
  string << "\n"
  string << divider_cells.join('-+-')
  string << "\n"
  data_rows.each do |data_cells|
    string << data_cells.join(' | ')
    string << "\n"
  end
  string
end