Class: Rbxl::Row
- Inherits:
-
Object
- Object
- Rbxl::Row
- Defined in:
- lib/rbxl/row.rb
Overview
Immutable row wrapper yielded by Rbxl::ReadOnlyWorksheet#each_row.
A row holds its 1-based worksheet index and a frozen array of cell objects. The cell array may contain Cell, ReadOnlyCell, or EmptyCell instances depending on the iteration options (pad_cells, expand_merged) and the parser backend in use.
sheet.each_row do |row|
row.index # => 2
row.size # => 3
row.values # => ["alice", 100, true]
row[0].value # => "alice"
end
Instance Attribute Summary collapse
-
#cells ⇒ Array<Rbxl::Cell, Rbxl::ReadOnlyCell, Rbxl::EmptyCell>
readonly
Frozen array of cell objects.
-
#index ⇒ Integer
readonly
1-based worksheet row number.
Instance Method Summary collapse
-
#[](offset) ⇒ Rbxl::Cell, ...
Returns the cell at a zero-based offset within the row.
-
#initialize(index:, cells:) ⇒ Row
constructor
A new instance of Row.
-
#size ⇒ Integer
Number of cells in the row.
-
#values ⇒ Array<Object>
Returns the row as plain Ruby values, memoized and frozen so that repeated calls are allocation-free.
Constructor Details
#initialize(index:, cells:) ⇒ Row
Returns a new instance of Row.
26 27 28 29 30 |
# File 'lib/rbxl/row.rb', line 26 def initialize(index:, cells:) @index = index @cells = cells.freeze @values = nil end |
Instance Attribute Details
#cells ⇒ Array<Rbxl::Cell, Rbxl::ReadOnlyCell, Rbxl::EmptyCell> (readonly)
Returns frozen array of cell objects.
21 22 23 |
# File 'lib/rbxl/row.rb', line 21 def cells @cells end |
#index ⇒ Integer (readonly)
Returns 1-based worksheet row number.
17 18 19 |
# File 'lib/rbxl/row.rb', line 17 def index @index end |
Instance Method Details
#[](offset) ⇒ Rbxl::Cell, ...
Returns the cell at a zero-based offset within the row.
No bounds checking is performed beyond Array semantics: an offset outside the cell range simply returns nil.
39 40 41 |
# File 'lib/rbxl/row.rb', line 39 def [](offset) cells[offset] end |
#size ⇒ Integer
Returns number of cells in the row.
52 53 54 |
# File 'lib/rbxl/row.rb', line 52 def size cells.size end |
#values ⇒ Array<Object>
Returns the row as plain Ruby values, memoized and frozen so that repeated calls are allocation-free.
47 48 49 |
# File 'lib/rbxl/row.rb', line 47 def values @values ||= cells.map(&:value).freeze end |