Class: Rasta::Spreadsheet::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/rasta/spreadsheet.rb

Overview

Records store the information of a particular row/col of a worksheet and allow iterating through the Record’s Cells

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet, index) ⇒ Record

Returns a new instance of Record.



405
406
407
408
409
410
# File 'lib/rasta/spreadsheet.rb', line 405

def initialize(sheet, index)
  @sheet       = sheet
  @book        = sheet.book
  @recordindex = index
  @range = @sheet.cellrange(@recordindex)
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



404
405
406
# File 'lib/rasta/spreadsheet.rb', line 404

def book
  @book
end

#recordindexObject (readonly)

Returns the value of attribute recordindex.



404
405
406
# File 'lib/rasta/spreadsheet.rb', line 404

def recordindex
  @recordindex
end

#sheetObject (readonly)

Returns the value of attribute sheet.



404
405
406
# File 'lib/rasta/spreadsheet.rb', line 404

def sheet
  @sheet
end

Instance Method Details

#[](index) ⇒ Object



426
427
428
# File 'lib/rasta/spreadsheet.rb', line 426

def [](index)
  Cell.new(@sheet, @recordindex, index)
end

#color=(c) ⇒ Object



423
424
425
# File 'lib/rasta/spreadsheet.rb', line 423

def color=(c)
  @range.Interior.ColorIndex = c
end

#dumpObject



432
433
434
435
436
# File 'lib/rasta/spreadsheet.rb', line 432

def dump
  vals = []
  self.each { |cell| vals << cell.value }
  return vals
end

#eachObject



411
412
413
414
415
416
417
418
419
# File 'lib/rasta/spreadsheet.rb', line 411

def each
  @sheet.headers.each_index do |cell_index| # should be a value for each header
    cell = @sheet.cell(@recordindex,cell_index + 1)
    next if cell.nil? # Make sure the header exists
    # Skip empty cells and italicized cells 
    next if (cell.value == '' || cell.italic)
    yield cell 
  end
end

#selectObject



420
421
422
# File 'lib/rasta/spreadsheet.rb', line 420

def select
  @range.Select
end

#to_sObject



429
430
431
# File 'lib/rasta/spreadsheet.rb', line 429

def to_s
  @sheet.style.to_s + ':' + @recordindex.to_s
end