Class: ActiveWorksheet::Adapters::FileAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- ActiveWorksheet::Adapters::FileAdapter
- Defined in:
- lib/active_worksheet/adapters/file_adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
"File"
Instance Attribute Summary
Attributes inherited from BaseAdapter
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #find(index) ⇒ Object
- #first ⇒ Object
-
#initialize(source: nil) ⇒ FileAdapter
constructor
A new instance of FileAdapter.
- #last ⇒ Object
Methods inherited from BaseAdapter
Constructor Details
#initialize(source: nil) ⇒ FileAdapter
Returns a new instance of FileAdapter.
10 11 12 13 14 |
# File 'lib/active_worksheet/adapters/file_adapter.rb', line 10 def initialize(source: nil) super(source: source) @workbook = Workbook::Book.open(source) end |
Instance Method Details
#all ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
43 44 45 |
# File 'lib/active_worksheet/adapters/file_adapter.rb', line 43 def count all.count end |
#find(index) ⇒ Object
31 32 33 |
# File 'lib/active_worksheet/adapters/file_adapter.rb', line 31 def find(index) all[index] end |
#first ⇒ Object
35 36 37 |
# File 'lib/active_worksheet/adapters/file_adapter.rb', line 35 def first find(0) end |
#last ⇒ Object
39 40 41 |
# File 'lib/active_worksheet/adapters/file_adapter.rb', line 39 def last find(-1) end |