Class: DataTable

Inherits:
Object
  • Object
show all
Defined in:
lib/source/data/data_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ DataTable

Returns a new instance of DataTable.



7
8
9
10
11
12
13
14
15
16
# File 'lib/source/data/data_table.rb', line 7

def initialize(table)
  self.str_count = table.length

  max_c=0
  table.each do |el|
    max_c = el.length if el.size > max_c
  end
  self.st_count = max_c
  self.table = table
end

Instance Attribute Details

#st_countObject

Returns the value of attribute st_count.



5
6
7
# File 'lib/source/data/data_table.rb', line 5

def st_count
  @st_count
end

#str_countObject

Returns the value of attribute str_count.



5
6
7
# File 'lib/source/data/data_table.rb', line 5

def str_count
  @str_count
end

Instance Method Details

#get_elem(str, st) ⇒ Object



19
20
21
22
23
# File 'lib/source/data/data_table.rb', line 19

def get_elem(str, st)
  return nil if str>=str_count
  return nil if st>=st_count
  table[str][st]
end

#to_my_arrayObject



25
26
27
# File 'lib/source/data/data_table.rb', line 25

def to_my_array
  table.dup
end

#to_sObject



29
30
31
# File 'lib/source/data/data_table.rb', line 29

def to_s
  table.map { |row| "[#{row.join(', ')}]" }.join("\n")
end