Class: Stockboy::Readers::Spreadsheet
- Inherits:
-
Stockboy::Reader
- Object
- Stockboy::Reader
- Stockboy::Readers::Spreadsheet
- Defined in:
- lib/stockboy/readers/spreadsheet.rb
Overview
Parse an Excel spreadsheet
Backed by Roo gem. See roo for other configuration options.
Instance Attribute Summary collapse
-
#first_row ⇒ Integer
Line number of first data row, starts counting at 1, like in Excel.
-
#format ⇒ Symbol
Spreadsheet format.
-
#header_row ⇒ Integer
Line number to look for headers, starts counting at 1, like in Excel.
-
#headers ⇒ Array
Override to set headers manually.
-
#last_row ⇒ Integer
Line number of last data row, use negative numbers to count back from end.
-
#options ⇒ Hash
Options passed to underlying Roo library.
-
#sheet ⇒ Integer
Spreadsheet sheet number, defaults to first.
Attributes inherited from Stockboy::Reader
Instance Method Summary collapse
-
#initialize(opts = {}, &block) ⇒ Spreadsheet
constructor
Initialize a new Spreadsheet reader.
- #parse(content) ⇒ Object
Constructor Details
#initialize(opts = {}, &block) ⇒ Spreadsheet
Initialize a new Spreadsheet reader
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 75 def initialize(opts={}, &block) super @format = opts[:format] || :xls @sheet = opts[:sheet] || :first @first_row = opts[:first_row] @last_row = opts[:last_row] @header_row = opts[:header_row] @headers = opts[:headers] @options = opts[:options] || {} DSL.new(self).instance_eval(&block) if block_given? end |
Instance Attribute Details
#first_row ⇒ Integer
Line number of first data row, starts counting at 1, like in Excel
43 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 43 dsl_attr :first_row |
#format ⇒ Symbol
Spreadsheet format
19 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 19 dsl_attr :format |
#header_row ⇒ Integer
Line number to look for headers, starts counting at 1, like in Excel
When specified without first_row
, then the next row becomes the first data row by default.
36 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 36 dsl_attr :header_row |
#headers ⇒ Array
Override to set headers manually
When specified, the first spreadsheet row is the default first data row, unless specified by first_row
.
60 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 60 dsl_attr :headers |
#last_row ⇒ Integer
Line number of last data row, use negative numbers to count back from end
50 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 50 dsl_attr :last_row |
#options ⇒ Hash
Options passed to underlying Roo library
67 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 67 dsl_attr :options |
#sheet ⇒ Integer
Spreadsheet sheet number, defaults to first
26 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 26 dsl_attr :sheet |
Instance Method Details
#parse(content) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/stockboy/readers/spreadsheet.rb', line 87 def parse(content) with_spreadsheet_tempfile(content) do |table| headers = table_headers(table) enum_data_rows(table).inject([]) do |rows, i| rows << Hash[headers.zip(table.row(i))] end end end |