Class: Xlsxrb::StreamRow
- Inherits:
-
Object
- Object
- Xlsxrb::StreamRow
- Defined in:
- lib/xlsxrb/stream_row.rb,
sig/generated/xlsxrb/stream_row.rbs
Overview
Streaming row implementation that parses cells on-demand / lazily. Provides O(1) memory consumption even for rows with tens of thousands of columns.
Instance Attribute Summary collapse
- #custom_height ⇒ Object readonly
- #height ⇒ Object readonly
- #hidden ⇒ Object readonly
- #index ⇒ Object readonly
- #outline_level ⇒ Object readonly
Instance Method Summary collapse
-
#[](col_index) ⇒ Elements::Cell, ...
Access a cell by 0-based column index, or access row attributes via Symbol.
-
#cell_at(col_index) ⇒ Elements::Cell?
Access a cell by 0-based column index.
-
#cells ⇒ Array<Elements::Cell>
Returns all cells as an Array.
-
#each {|cell| ... } ⇒ Enumerator, void
Iterate over cells in this streaming row.
-
#each_cell {|cell| ... } ⇒ Enumerator, void
Iterate over cells in this streaming row one by one.
-
#errors ⇒ Array<String>
Validation errors for compatibility with Elements::Row.
-
#initialize(index:, xml_bytes:, from:, to:, shared_strings:, height: nil, hidden: false, custom_height: false, outline_level: nil) ⇒ StreamRow
constructor
: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void.
-
#inspect ⇒ String
Human-readable representation.
-
#to_a ⇒ Array<Object>
Convert row cells to an Array of raw values (sparse columns get nil).
-
#unmapped_data ⇒ Hash
Unmapped metadata for compatibility with Elements::Row.
-
#valid? ⇒ Boolean
Returns whether the row is valid according to OOXML specifications.
-
#values ⇒ Array<Object>
Returns cell values as an Array.
Constructor Details
#initialize(index:, xml_bytes:, from:, to:, shared_strings:, height: nil, hidden: false, custom_height: false, outline_level: nil) ⇒ StreamRow
: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/xlsxrb/stream_row.rb', line 34 def initialize(index:, xml_bytes:, from:, to:, shared_strings:, height: nil, hidden: false, custom_height: false, outline_level: nil) @index = index @xml = xml_bytes @from = from @to = to @shared_strings = shared_strings @height = height @hidden = hidden @custom_height = custom_height @outline_level = outline_level @cells_cache = nil end |
Instance Attribute Details
#custom_height ⇒ Object (readonly)
22 23 24 |
# File 'lib/xlsxrb/stream_row.rb', line 22 def custom_height @custom_height end |
#height ⇒ Object (readonly)
22 23 24 |
# File 'lib/xlsxrb/stream_row.rb', line 22 def height @height end |
#hidden ⇒ Object (readonly)
22 23 24 |
# File 'lib/xlsxrb/stream_row.rb', line 22 def hidden @hidden end |
#index ⇒ Object (readonly)
22 23 24 |
# File 'lib/xlsxrb/stream_row.rb', line 22 def index @index end |
#outline_level ⇒ Object (readonly)
22 23 24 |
# File 'lib/xlsxrb/stream_row.rb', line 22 def outline_level @outline_level end |
Instance Method Details
#[](col_index) ⇒ Elements::Cell, ...
Access a cell by 0-based column index, or access row attributes via Symbol.
: (Integer | Symbol col_index) -> untyped
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/xlsxrb/stream_row.rb', line 93 def [](col_index) case col_index when Symbol case col_index when :cells then cells when :index then index when :height then height when :hidden then hidden when :custom_height then custom_height when :outline_level then outline_level when :attrs then { height: height, hidden: hidden, custom_height: custom_height, outline_level: outline_level } end else cells[col_index] end end |
#cell_at(col_index) ⇒ Elements::Cell?
Access a cell by 0-based column index.
: (Integer col_index) -> Elements::Cell?
116 117 118 |
# File 'lib/xlsxrb/stream_row.rb', line 116 def cell_at(col_index) cells.find { |c| c.column_index == col_index } end |
#cells ⇒ Array<Elements::Cell>
Returns all cells as an Array. Cached on first access.
: () -> Array
83 84 85 |
# File 'lib/xlsxrb/stream_row.rb', line 83 def cells @cells ||= each_cell.to_a.freeze end |
#each {|cell| ... } ⇒ Enumerator, void
Iterate over cells in this streaming row.
: () { (Elements::Cell) -> void } -> void : | () -> Enumerator[Elements::Cell, void]
74 75 76 |
# File 'lib/xlsxrb/stream_row.rb', line 74 def each(&) each_cell(&) end |
#each_cell {|cell| ... } ⇒ Enumerator, void
Iterate over cells in this streaming row one by one.
: () { (Elements::Cell) -> void } -> void : | () -> Enumerator[Elements::Cell, void]
56 57 58 59 60 61 62 63 64 |
# File 'lib/xlsxrb/stream_row.rb', line 56 def each_cell(&) return enum_for(:each_cell) unless block_given? if @cells @cells.each(&) else Ooxml::WorksheetParser.fast_scan_cells_direct(@xml, @from, @to, @shared_strings, { row: @index }, &) end end |
#errors ⇒ Array<String>
Validation errors for compatibility with Elements::Row.
: () -> Array
168 169 170 |
# File 'lib/xlsxrb/stream_row.rb', line 168 def errors Elements::EMPTY_ERRORS end |
#inspect ⇒ String
Human-readable representation.
: () -> String
177 178 179 |
# File 'lib/xlsxrb/stream_row.rb', line 177 def inspect "#<#{self.class.name} index=#{index} height=#{height.inspect} hidden=#{hidden}>" end |
#to_a ⇒ Array<Object>
Convert row cells to an Array of raw values (sparse columns get nil).
: () -> Array
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/xlsxrb/stream_row.rb', line 125 def to_a return [] if cells.empty? max_col = cells.map(&:column_index).max || 0 arr = Array.new(max_col + 1) cells.each do |cell| arr[cell.column_index] = cell.value end arr end |
#unmapped_data ⇒ Hash
Unmapped metadata for compatibility with Elements::Row.
: () -> Hash[untyped, untyped]
159 160 161 |
# File 'lib/xlsxrb/stream_row.rb', line 159 def unmapped_data Elements::EMPTY_HASH end |
#valid? ⇒ Boolean
Returns whether the row is valid according to OOXML specifications.
: () -> bool
150 151 152 |
# File 'lib/xlsxrb/stream_row.rb', line 150 def valid? true end |
#values ⇒ Array<Object>
Returns cell values as an Array.
: () -> Array
141 142 143 |
# File 'lib/xlsxrb/stream_row.rb', line 141 def values to_a end |