Class: DataTable

Inherits:
Object
  • Object
show all
Defined in:
lib/repositories/containers/data_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_countObject

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_countObject

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_arrayObject



23
24
25
# File 'lib/repositories/containers/data_table.rb', line 23

def to_2d_array
  table.dup
end

#to_sObject



27
28
29
# File 'lib/repositories/containers/data_table.rb', line 27

def to_s
  "DataTable (#{rows_count}x#{cols_count})"
end