Class: Ditch::Sheet
- Inherits:
-
Object
- Object
- Ditch::Sheet
- Defined in:
- lib/ditch/sheet.rb
Overview
Class wrapping the Creek::Sheet class for adding small things
Instance Attribute Summary collapse
-
#creek_sheet ⇒ Object
readonly
Returns the value of attribute creek_sheet.
Instance Method Summary collapse
-
#headers ⇒ Object
Retrieve headers, if :first_row_is_header option is set.
-
#initialize(sheet, options = {}) ⇒ Sheet
constructor
Create a Ditch::Sheet *
sheetCreek::Sheet to make the base *optionsOptions to control the behaviour of the sheet. -
#rows ⇒ Object
Enumerate the Rows in the given Sheet, As Ditch::IndexedRows.
Constructor Details
#initialize(sheet, options = {}) ⇒ Sheet
Create a Ditch::Sheet
-
sheetCreek::Sheet to make the base -
optionsOptions to control the behaviour of the sheet
9 10 11 12 13 14 15 |
# File 'lib/ditch/sheet.rb', line 9 def initialize(sheet,={}) @creek_sheet = sheet @opts = if @opts[:first_row_is_header] @headers = headers end end |
Instance Attribute Details
#creek_sheet ⇒ Object (readonly)
Returns the value of attribute creek_sheet.
4 5 6 |
# File 'lib/ditch/sheet.rb', line 4 def creek_sheet @creek_sheet end |
Instance Method Details
#headers ⇒ Object
Retrieve headers, if :first_row_is_header option is set
18 19 20 21 22 23 24 25 |
# File 'lib/ditch/sheet.rb', line 18 def headers headers = Hash.new header_row = @creek_sheet.rows.first header_row.each_key do |k| headers[header_row[k]]= k.gsub(/\d/,'') end headers end |
#rows ⇒ Object
Enumerate the Rows in the given Sheet, As Ditch::IndexedRows
28 29 30 31 32 33 34 35 36 |
# File 'lib/ditch/sheet.rb', line 28 def rows Enumerator.new do |y| @creek_sheet.rows.each_with_index do |row, index| unless index == 0 && @opts[:first_row_is_header] y << Ditch::IndexedRow.new(@headers, index+1, row) end end end end |