class Tablespoon::Record

Attributes

data[RW]
id[RW]
row_num[RW]

Public Class Methods

new( table ) click to toggle source
# File lib/tablespoon.rb, line 182
def initialize( table )
  
  @table      = table
  
  @field_map  = table.field_map
  @ws         = table.ws
  @id_field   = table.id_field
  
  @data  = {}
  
end

Public Instance Methods

[](field) click to toggle source
# File lib/tablespoon.rb, line 142
def [] (field)
  return @data[field]
end
[]=(field,value) click to toggle source
# File lib/tablespoon.rb, line 146
def []= (field,value)

  ## get the column number where we think it is
  ## if it's not there, rebuild the field map
  ## and try again
  
  col_num = get_col_num( field )
  row_num = @row_num
  
  @ws[row_num, col_num] = value

  @ws.save
  
  if field == @id_field
    @id = value
  end
  
end
get_col_num( field ) click to toggle source
# File lib/tablespoon.rb, line 165
def get_col_num( field )

  col_num = @field_map[field]

  if ! @ws[1,col_num] == field
    @table.build_column_map
    col_num = @field_map[field]
    
    if ! @ws[1,col_num] == field
      raise "Unable to find field #{field}"
    end
  end
  
  return col_num

end
to_s() click to toggle source
# File lib/tablespoon.rb, line 194
def to_s
  return "Row #{@row_num} Id #{@id} " + @data.keys.collect { |a| "#{a}: #{@data[a]}" }.join(' - ')
end