Class: Xlsxrb::Elements::Row
- Inherits:
-
Data
- Object
- Data
- Xlsxrb::Elements::Row
- Includes:
- Enumerable
- Defined in:
- lib/xlsxrb/elements/row.rb,
sig/generated/xlsxrb/elements/row.rbs
Overview
Represents a single row in a worksheet. index is 0-based.
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#custom_height ⇒ Object
readonly
Returns the value of attribute custom_height.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#outline_level ⇒ Object
readonly
Returns the value of attribute outline_level.
-
#unmapped_data ⇒ Object
readonly
Returns the value of attribute unmapped_data.
Class Method Summary collapse
- .members ⇒ [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
- .new ⇒ Object
- .validate(index, cells) ⇒ Object
Instance Method Summary collapse
- #[](col_index) ⇒ Object
-
#cell_at(column_index) ⇒ Object
Returns the cell at the given 0-based column index, or nil.
- #each ⇒ Object
- #each_cell ⇒ Object
-
#initialize(index:, cells: EMPTY_CELLS, height: nil, hidden: false, custom_height: false, outline_level: nil, unmapped_data: EMPTY_HASH, errors: nil) ⇒ Row
constructor
A new instance of Row.
- #members ⇒ [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
- #to_a ⇒ Object
- #valid? ⇒ Boolean
-
#values ⇒ Object
Returns cell values as an Array (sparse columns get nil).
Constructor Details
#initialize(index:, cells: EMPTY_CELLS, height: nil, hidden: false, custom_height: false, outline_level: nil, unmapped_data: EMPTY_HASH, errors: nil) ⇒ Row
Returns a new instance of Row.
12 13 14 15 16 17 18 19 20 |
# File 'lib/xlsxrb/elements/row.rb', line 12 def initialize(index:, cells: EMPTY_CELLS, height: nil, hidden: false, custom_height: false, outline_level: nil, unmapped_data: EMPTY_HASH, errors: nil) computed_errors = errors || self.class.validate(index, cells) computed_errors = computed_errors.freeze unless computed_errors.frozen? cells = cells.freeze unless cells.frozen? super(index: index, cells: cells, height: height, hidden: hidden, custom_height: custom_height, outline_level: outline_level, unmapped_data: unmapped_data, errors: computed_errors) end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def cells @cells end |
#custom_height ⇒ Object (readonly)
Returns the value of attribute custom_height
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def custom_height @custom_height end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def errors @errors end |
#height ⇒ Object (readonly)
Returns the value of attribute height
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def height @height end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def hidden @hidden end |
#index ⇒ Object (readonly)
Returns the value of attribute index
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def index @index end |
#outline_level ⇒ Object (readonly)
Returns the value of attribute outline_level
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def outline_level @outline_level end |
#unmapped_data ⇒ Object (readonly)
Returns the value of attribute unmapped_data
9 10 11 |
# File 'lib/xlsxrb/elements/row.rb', line 9 def unmapped_data @unmapped_data end |
Class Method Details
.members ⇒ [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
27 |
# File 'sig/generated/xlsxrb/elements/row.rbs', line 27
def self.members: () -> [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
|
.new(index, cells, height, hidden, custom_height, outline_level, unmapped_data, errors) ⇒ instance .new(index:, cells:, height:, hidden:, custom_height:, outline_level:, unmapped_data:, errors:) ⇒ instance
24 25 |
# File 'sig/generated/xlsxrb/elements/row.rbs', line 24
def self.new: (untyped index, untyped cells, untyped height, untyped hidden, untyped custom_height, untyped outline_level, untyped unmapped_data, untyped errors) -> instance
| (index: untyped, cells: untyped, height: untyped, hidden: untyped, custom_height: untyped, outline_level: untyped, unmapped_data: untyped, errors: untyped) -> instance
|
.validate(index, cells) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/xlsxrb/elements/row.rb', line 81 def self.validate(index, cells) return EMPTY_ERRORS if index.is_a?(Integer) && index >= 0 && index < 1_048_576 && cells.is_a?(Array) errs = [] if !index.is_a?(Integer) || index.negative? errs << "index must be a non-negative Integer (got #{index.inspect})" elsif index >= 1_048_576 errs << "index must be < 1048576 (got #{index}, max row is 1048576)" end errs << "cells must be an Array (got #{cells.class})" unless cells.is_a?(Array) errs end |
Instance Method Details
#[](col_index) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xlsxrb/elements/row.rb', line 22 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(column_index) ⇒ Object
Returns the cell at the given 0-based column index, or nil.
67 68 69 |
# File 'lib/xlsxrb/elements/row.rb', line 67 def cell_at(column_index) cells.find { |c| c.column_index == column_index } end |
#each ⇒ Object
39 40 41 42 43 |
# File 'lib/xlsxrb/elements/row.rb', line 39 def each(&) return to_enum(:each) unless block_given? cells.each(&) end |
#each_cell ⇒ Object
45 46 47 48 49 |
# File 'lib/xlsxrb/elements/row.rb', line 45 def each_cell(&) return to_enum(:each_cell) unless block_given? cells.each(&) end |
#members ⇒ [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
29 |
# File 'sig/generated/xlsxrb/elements/row.rbs', line 29
def members: () -> [ :index, :cells, :height, :hidden, :custom_height, :outline_level, :unmapped_data, :errors ]
|
#to_a ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xlsxrb/elements/row.rb', line 51 def to_a return [] if cells.empty? max_col = cells.map(&:column_index).max arr = Array.new(max_col + 1) cells.each do |cell| arr[cell.column_index] = cell.value end arr end |
#valid? ⇒ Boolean
62 63 64 |
# File 'lib/xlsxrb/elements/row.rb', line 62 def valid? errors.empty? end |
#values ⇒ Object
Returns cell values as an Array (sparse columns get nil).
72 73 74 75 76 77 78 79 |
# File 'lib/xlsxrb/elements/row.rb', line 72 def values return [] if cells.empty? max_col = cells.max_by(&:column_index).column_index result = Array.new(max_col + 1) cells.each { |c| result[c.column_index] = c.value } result end |