Class: Extract::Table

Inherits:
Object show all
Includes:
FromHash
Defined in:
lib/extract/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cell_rangeObject

Returns the value of attribute cell_range.



31
32
33
# File 'lib/extract/table.rb', line 31

def cell_range
  @cell_range
end

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/extract/table.rb', line 31

def name
  @name
end

#sheet_defObject

Returns the value of attribute sheet_def.



31
32
33
# File 'lib/extract/table.rb', line 31

def sheet_def
  @sheet_def
end

Instance Method Details

#cell_objsObject



37
38
39
# File 'lib/extract/table.rb', line 37

def cell_objs
  cells.map { |c| Cell.new(:sheet_def => sheet_def, :cell => c) }
end

#cell_row_hashObject



40
41
42
43
44
45
46
# File 'lib/extract/table.rb', line 40

def cell_row_hash
  res = Hash.new { |h,k| h[k] = [] }
  cell_objs.each do |c|
    res[c.row] << c
  end
  res
end

#cellsObject



33
34
35
# File 'lib/extract/table.rb', line 33

def cells
  Extract.expand_cells(cell_range)
end

#field_namesObject



48
49
50
51
# File 'lib/extract/table.rb', line 48

def field_names
  k = cell_row_hash.keys.min
  cell_row_hash[k].map { |x| x.value }
end

#rowsObject



53
54
55
# File 'lib/extract/table.rb', line 53

def rows
  cell_row_hash.values[1..-1].map { |a| Row.new(:table => self, :cells => a) }.select { |x| x.present? }
end

#sql_statementsObject



57
58
59
60
61
62
63
# File 'lib/extract/table.rb', line 57

def sql_statements
  res = Extract::Export::Table.new(:name => name)
  rows.each do |row|
    res.rows << row.value_hash
  end
  res.sql_statements
end