Class: PrimeTime::Table

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

Direct Known Subclasses

PrimeTable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 1, height: 1) ⇒ Table

Returns a new instance of Table.



5
6
7
8
9
10
11
12
13
14
# File 'lib/prime_time/table.rb', line 5

def initialize(width: 1, height: 1)
  @width = width
  @height = height
  @col_headers = Array.new(width).fill(' ')
  @row_headers = Array.new(height).fill(' ')
  @rows = Array.new
  height.times do
    @rows << Array.new(width).fill('-')
  end
end

Instance Attribute Details

#col_headersObject

Returns the value of attribute col_headers.



3
4
5
# File 'lib/prime_time/table.rb', line 3

def col_headers
  @col_headers
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/prime_time/table.rb', line 3

def height
  @height
end

#row_headersObject

Returns the value of attribute row_headers.



3
4
5
# File 'lib/prime_time/table.rb', line 3

def row_headers
  @row_headers
end

#rowsObject

Returns the value of attribute rows.



3
4
5
# File 'lib/prime_time/table.rb', line 3

def rows
  @rows
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/prime_time/table.rb', line 3

def width
  @width
end

Instance Method Details

#to_sObject



16
17
18
19
20
21
22
23
24
# File 'lib/prime_time/table.rb', line 16

def to_s
  String.new.tap { |table_string|
    table_string << col_header_string

    self.rows.each_with_index do |r, i|
      table_string << row_string(r, i)
    end
  }.to_s.strip
end