Class: RgGen::SpreadsheetLoader::Spreadsheet::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book, sheet) ⇒ Sheet

Returns a new instance of Sheet.



7
8
9
10
11
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 7

def initialize(book, sheet)
  @file = book.file
  @sheet = sheet
  @rows = []
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



13
14
15
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 13

def file
  @file
end

#sheetObject (readonly)

Returns the value of attribute sheet.



14
15
16
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 14

def sheet
  @sheet
end

Instance Method Details

#[](row, column = nil) ⇒ Object



16
17
18
19
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 16

def [](row, column = nil)
  @rows[row] ||= Row.new(self, row)
  (column && @rows[row][column]) || @rows[row]
end

#from_table(table) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 21

def from_table(table)
  table.each_with_index do |row, row_index|
    row.each_with_index do |value, column_index|
      self[row_index][column_index] = value
    end
  end
end

#rows(from = 0, length = nil) ⇒ Object



29
30
31
# File 'lib/rggen/spreadsheet_loader/spreadsheet/sheet.rb', line 29

def rows(from = 0, length = nil)
  Array.new(length || (@rows.size - from)) { |i| self[from + i] }
end