Class: Sheetah::Backends::Xlsx
- Inherits:
-
Object
- Object
- Sheetah::Backends::Xlsx
- Includes:
- Sheet
- Defined in:
- lib/sheetah/backends/xlsx.rb
Constant Summary
Constants included from Sheet
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #each_header ⇒ Object
- #each_row ⇒ Object
-
#initialize(path:) ⇒ Xlsx
constructor
A new instance of Xlsx.
Methods included from Sheet
Constructor Details
Class Method Details
.register(registry = Backends.registry) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sheetah/backends/xlsx.rb', line 16 def self.register(registry = Backends.registry) registry.set(self) do |args, opts| next false unless args.empty? case opts in { path: /\.xlsx$/i, **nil } true else false end end end |
Instance Method Details
#close ⇒ Object
75 76 77 78 79 |
# File 'lib/sheetah/backends/xlsx.rb', line 75 def close @roo.close nil end |
#each_header ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sheetah/backends/xlsx.rb', line 38 def each_header return to_enum(:each_header) { @cols_count } unless block_given? @headers.each_with_index do |header, col_idx| col = Sheet.int2col(col_idx + 1) yield Header.new(col: col, value: header) end self end |
#each_row ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sheetah/backends/xlsx.rb', line 50 def each_row return to_enum(:each_row) unless block_given? return if @is_empty first_row = 2 last_row = worksheet.last_row row = 0 first_row.upto(last_row) do |cursor| raw = worksheet.row(cursor) row += 1 value = Array.new(@cols_count) do |col_idx| col = Sheet.int2col(col_idx + 1) Cell.new(row: row, col: col, value: raw[col_idx]) end yield Row.new(row: row, value: value) end self end |