class ActiveWorksheet::Adapters::FileAdapter

Constants

ADAPTER_NAME

Public Class Methods

new(source: nil) click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 10
def initialize(source: nil)
  super(source: source)

  @workbook = Workbook::Book.open(source)
end

Public Instance Methods

all() click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 16
def all
  table = @workbook.sheet.table

  headers = table.shift.map do |header|
    ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.parameterize(header.value))
  end

  table.map do |row|
    row.each_with_index.reduce({}) do |result, (cell, index)|
      result[headers[index]] = cell.value
      result
    end
  end
end
count() click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 43
def count
  all.count
end
find(index) click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 31
def find(index)
  all[index]
end
first() click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 35
def first
  find(0)
end
last() click to toggle source
# File lib/active_worksheet/adapters/file_adapter.rb, line 39
def last
  find(-1)
end