Class: SpreadsheetGoodies::AbstractBaseWorksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_goodies/abstract_base_worksheet.rb

Direct Known Subclasses

Excel::Worksheet, GoogleDrive::Worksheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#header_rowObject (readonly)

Returns the value of attribute header_row.



5
6
7
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 5

def header_row
  @header_row
end

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 5

def rows
  @rows
end

Instance Method Details

#[](index) ⇒ Object



7
8
9
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 7

def [](index)
  @rows[index]
end

#commit_writes!Object

Some adapters (like GoogleDrive) require writes to be committed to actually make the changes on the spreadsheet



35
36
37
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 35

def commit_writes!
  raise 'this kind of worksheet does not require writes to be committed'
end

#data_rowsObject

Return only the rows that contain data (excludes the header rows)



12
13
14
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 12

def data_rows
  @rows[@num_header_rows..-1]
end

#find_row_by_column_value(column_title, cell_value) ⇒ Object

Finds and returns the first row that contains cell_value at the given column



17
18
19
20
21
22
23
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 17

def find_row_by_column_value(column_title, cell_value)
  data_rows.each do |row|
    return row if row[column_title] == cell_value
  end

  nil
end

#write_to_cell(row_index, col_index, value) ⇒ Object

Writes to a given cell identified by row and column indexes (they start at 1) This method should be overriden by worksheets that wish to implement writes. Usually this method is not called directly by the gem user, but rather from the modified row itself



29
30
31
# File 'lib/spreadsheet_goodies/abstract_base_worksheet.rb', line 29

def write_to_cell(row_index, col_index, value)
  raise 'writes are not implemented for this type of worksheet'
end