Class: SimpleExcel::Worksheet
- Inherits:
-
Object
- Object
- SimpleExcel::Worksheet
- Defined in:
- lib/simple-excel/worksheet.rb
Defined Under Namespace
Classes: FileWithoutData, HeadersDoNotMatch
Instance Attribute Summary collapse
- #excel ⇒ Object readonly
- #headers ⇒ Object readonly
- #sheet ⇒ Object readonly
Instance Method Summary collapse
-
#each {|row| ... } ⇒ Object
Pass all rows excel file.
-
#initialize(excel, headers, check_headers = true) ⇒ Object
constructor
Create new instance of SimpleExcel::Worksheet.
-
#to_s ⇒ String
Class name.
Constructor Details
#initialize(excel, headers, check_headers = true) ⇒ Object
Create new instance of SimpleExcel::Worksheet
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/simple-excel/worksheet.rb', line 17 def initialize(excel, headers, check_headers = true) @excel, @headers = excel, headers if check_headers @excel.worksheets.each_with_index do |sheet, index| @sheet = @excel.worksheet(index) return @sheet if @headers == sheet.row(0) end raise HeadersDoNotMatch, "File headers do not coincide with #{@headers}" else @sheet = @excel.worksheet(0) end end |
Instance Attribute Details
#excel ⇒ Object (readonly)
8 9 10 |
# File 'lib/simple-excel/worksheet.rb', line 8 def excel @excel end |
#headers ⇒ Object (readonly)
8 9 10 |
# File 'lib/simple-excel/worksheet.rb', line 8 def headers @headers end |
#sheet ⇒ Object (readonly)
8 9 10 |
# File 'lib/simple-excel/worksheet.rb', line 8 def sheet @sheet end |
Instance Method Details
#each {|row| ... } ⇒ Object
Pass all rows excel file
40 41 42 43 44 45 46 |
# File 'lib/simple-excel/worksheet.rb', line 40 def each raise FileWithoutData, 'File contains no data' if no_data? (1..@sheet.last_row_index).each do |i| row = get_values(i) yield row end end |
#to_s ⇒ String
Returns Class name.
32 33 34 |
# File 'lib/simple-excel/worksheet.rb', line 32 def to_s self.class end |