class Spreadshot::Backends::SmarterCSVBackend

Adapter for the SmarterCSV Gem ({github.com/tilo/smarter_csv})

Public Class Methods

new(options = {}) click to toggle source

Returns a new instance of SmarterCSVBackend (See {ReaderBackend#initialize Spreadshot::ReaderBackends::ReaderBackend}) @param [Hash] options @note Ignores :header option

# File lib/spreadshot/backends/smarter_csv_backend.rb, line 12
def initialize(options = {})
  options ||= {}
  options[:headers] = true
  super(options)
end

Public Instance Methods

read(path_to_spreadsheet) { |current_row_index, current_row_data| ... } click to toggle source

Reads data from the specified CSV file (See {ReaderBackend#read Spreadshot::ReaderBackends::ReaderBackend})

@param [String] path_to_spreadsheet

@yield [row_index, row_data] @yieldparam [Integer] row_index

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

@yieldparam [Hash] row_data

A hash representation of the data read from the current row

@raise [Spreadshot::ReaderError]

# File lib/spreadshot/backends/smarter_csv_backend.rb, line 33
def read(path_to_spreadsheet)
  SmarterCSV.process(path_to_spreadsheet) do |row|
    current_row_data = row.first
    yield(@current_row_index, current_row_data)
    @current_row_index += 1
  end
rescue => e
  raise Spreadshot::ReaderError, e.message
end