Class: DataTable
- Inherits:
-
Object
- Object
- DataTable
- Defined in:
- lib/source/repositories/containers/data_table.rb
Instance Attribute Summary collapse
-
#cols_count ⇒ Object
readonly
Returns the value of attribute cols_count.
-
#rows_count ⇒ Object
readonly
Returns the value of attribute rows_count.
Instance Method Summary collapse
- #get_item(row, col) ⇒ Object
-
#initialize(table) ⇒ DataTable
constructor
A new instance of DataTable.
- #to_my_array ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(table) ⇒ DataTable
Returns a new instance of DataTable.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/source/repositories/containers/data_table.rb', line 7 def initialize(table) self.rows_count = table.length max_cols = 0 table.each do |row| max_cols = row.length if row.size > max_cols end self.cols_count = max_cols self.table = table end |
Instance Attribute Details
#cols_count ⇒ Object
Returns the value of attribute cols_count.
5 6 7 |
# File 'lib/source/repositories/containers/data_table.rb', line 5 def cols_count @cols_count end |
#rows_count ⇒ Object
Returns the value of attribute rows_count.
5 6 7 |
# File 'lib/source/repositories/containers/data_table.rb', line 5 def rows_count @rows_count end |
Instance Method Details
#get_item(row, col) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/source/repositories/containers/data_table.rb', line 18 def get_item(row, col) return nil if row >= rows_count || row.negative? return nil if col >= cols_count || col.negative? table[row][col] end |
#to_my_array ⇒ Object
25 26 27 |
# File 'lib/source/repositories/containers/data_table.rb', line 25 def to_my_array table.dup end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/source/repositories/containers/data_table.rb', line 29 def to_s table.map { |row| "[#{row.join(', ')}]" }.join("\n") end |