Class: Rbxl::Row

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(index:, cells:) ⇒ Row

Returns a new instance of Row.

Parameters:



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

#cellsArray<Rbxl::Cell, Rbxl::ReadOnlyCell, Rbxl::EmptyCell> (readonly)

Returns frozen array of cell objects.

Returns:



21
22
23
# File 'lib/rbxl/row.rb', line 21

def cells
  @cells
end

#indexInteger (readonly)

Returns 1-based worksheet row number.

Returns:

  • (Integer)

    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.

Parameters:

  • offset (Integer)

    zero-based position within the row

Returns:



39
40
41
# File 'lib/rbxl/row.rb', line 39

def [](offset)
  cells[offset]
end

#sizeInteger

Returns number of cells in the row.

Returns:

  • (Integer)

    number of cells in the row



52
53
54
# File 'lib/rbxl/row.rb', line 52

def size
  cells.size
end

#valuesArray<Object>

Returns the row as plain Ruby values, memoized and frozen so that repeated calls are allocation-free.

Returns:

  • (Array<Object>)

    decoded cell values in column order



47
48
49
# File 'lib/rbxl/row.rb', line 47

def values
  @values ||= cells.map(&:value).freeze
end