Class: PrimeTime::Table
- Inherits:
-
Object
- Object
- PrimeTime::Table
- Defined in:
- lib/prime_time/table.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#col_headers ⇒ Object
Returns the value of attribute col_headers.
-
#height ⇒ Object
Returns the value of attribute height.
-
#row_headers ⇒ Object
Returns the value of attribute row_headers.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(width: 1, height: 1) ⇒ Table
constructor
A new instance of Table.
- #to_s ⇒ Object
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_headers ⇒ Object
Returns the value of attribute col_headers.
3 4 5 |
# File 'lib/prime_time/table.rb', line 3 def col_headers @col_headers end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/prime_time/table.rb', line 3 def height @height end |
#row_headers ⇒ Object
Returns the value of attribute row_headers.
3 4 5 |
# File 'lib/prime_time/table.rb', line 3 def row_headers @row_headers end |
#rows ⇒ Object
Returns the value of attribute rows.
3 4 5 |
# File 'lib/prime_time/table.rb', line 3 def rows @rows end |
#width ⇒ Object
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_s ⇒ Object
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 |