Class: DataTable
- Inherits:
-
Object
- Object
- DataTable
- Defined in:
- lib/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
Получить значение в ячейке [row, col].
-
#initialize(table) ⇒ DataTable
constructor
Конструктор, принимает 2D Array.
- #to_2d_array ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(table) ⇒ DataTable
Конструктор, принимает 2D Array
7 8 9 10 11 12 13 |
# File 'lib/repositories/containers/data_table.rb', line 7 def initialize(table) self.rows_count = table.size max_cols = 0 table.each { |row| max_cols = row.size if row.size > max_cols } self.cols_count = max_cols self.table = table end |
Instance Attribute Details
#cols_count ⇒ Object
Returns the value of attribute cols_count.
4 5 6 |
# File 'lib/repositories/containers/data_table.rb', line 4 def cols_count @cols_count end |
#rows_count ⇒ Object
Returns the value of attribute rows_count.
4 5 6 |
# File 'lib/repositories/containers/data_table.rb', line 4 def rows_count @rows_count end |
Instance Method Details
#get_item(row, col) ⇒ Object
Получить значение в ячейке [row, col]
16 17 18 19 20 21 |
# File 'lib/repositories/containers/data_table.rb', line 16 def get_item(row, col) return nil if row >= rows_count return nil if col >= cols_count table[row][col].dup end |
#to_2d_array ⇒ Object
23 24 25 |
# File 'lib/repositories/containers/data_table.rb', line 23 def to_2d_array table.dup end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/repositories/containers/data_table.rb', line 27 def to_s "DataTable (#{rows_count}x#{cols_count})" end |