Class: Spreadshot::Backends::ReaderBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadshot/backends/reader_backend.rb

Overview

Base class for all spreadshot reader backends.

Direct Known Subclasses

RubyXLBackend, SmarterCSVBackend

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ReaderBackend

Returns a new instance of ReaderBackend.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :headers (Boolean)

    Specifies whether the spreadsheet to be read contains headers


10
11
12
13
14
# File 'lib/spreadshot/backends/reader_backend.rb', line 10

def initialize(options = {})
  options ||= {}
  @headers = (options.has_key?(:headers)) ? options[:headers] : true
  @current_row_index = @headers ? 2 : 1
end

Instance Method Details

#read(path_to_spreadsheet) {|row_index, row_data| ... } ⇒ Object

Note:

Must be overriden by subclasses. Override must raise Spreadshot::ReaderError if something goes wrong while reading

Reads data from the specified spreadsheet

Parameters:

  • path_to_spreadsheet (String)

Yields:

  • (row_index, row_data)

Yield Parameters:

  • row_index (Integer)

    The index of the current row being read. The first row has an index of 1

  • row_data (Hash)

    A hash representation of the data read from the current row

Raises:

  • (NotImplementedError)

32
33
34
# File 'lib/spreadshot/backends/reader_backend.rb', line 32

def read(path_to_spreadsheet)
  raise NotImplementedError
end