Class: CSVPlusPlus::Row

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/row.rb

Overview

A row of a template. A row contains an Array of Cells and possibly a row-level Modifier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cells:, index:, modifier:) ⇒ Row



28
29
30
31
32
# File 'lib/csv_plus_plus/row.rb', line 28

def initialize(cells:, index:, modifier:)
  @cells = cells
  @modifier = modifier
  @index = index
end

Instance Attribute Details

#cellsArray<Cell> (readonly)

The cells contained by this row.



10
11
12
# File 'lib/csv_plus_plus/row.rb', line 10

def cells
  @cells
end

#indexInteger

The index of this row. Starts at 0.



10
11
12
# File 'lib/csv_plus_plus/row.rb', line 10

def index
  @index
end

#modifierModifier (readonly)

The modifier to apply to all cells in this row



10
11
12
# File 'lib/csv_plus_plus/row.rb', line 10

def modifier
  @modifier
end

Instance Method Details

#expand_amountInteger

How much this row will expand itself, if at all (0)



47
48
49
50
51
# File 'lib/csv_plus_plus/row.rb', line 47

def expand_amount
  return 0 if @modifier.expand.nil?

  ::T.must(@modifier.expand).repetitions || (1000 - @index)
end

#expand_rows(starts_at:, into: []) ⇒ Array<Row>

Starting at starts_at, do a deep copy of this row into the Array referenced by into.



60
61
62
63
64
65
66
67
68
69
# File 'lib/csv_plus_plus/row.rb', line 60

def expand_rows(starts_at:, into: [])
  return into if @modifier.expand.nil?

  ::T.must(@modifier.expand).starts_at = starts_at

  starts_at.upto(expand_amount + starts_at - 1) do |row_index|
    into << deep_clone.tap { |c| c.index = row_index }
  end
  into
end

#unexpanded?T::Boolean

Does the row have an ![[expand]] modifier but is yet to be expanded?



75
76
77
78
79
# File 'lib/csv_plus_plus/row.rb', line 75

def unexpanded?
  return false if @modifier.expand.nil?

  !::T.must(@modifier.expand).expanded?
end