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

Returns a new instance of Row.

Parameters:

  • cells (Array<Cell>)

    The cells belonging to this row

  • index (Integer)

    The index of this row (starts at 0)

  • modifier (Modifier)

    The modifier to apply to all cells in this 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.

Returns:

  • (Array<Cell>)

    the current value of cells



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.

Returns:

  • (Integer)

    the current value of index



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

Returns:

  • (Modifier)

    the current value of modifier



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)

Returns:

  • (Integer)


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.

Parameters:

  • starts_at (Integer)

    The row_index where this row was expanded.

  • into (Array<Row>) (defaults to: [])

    An array where the expanded rows will be accumulated.

Returns:

  • (Array<Row>)

    The rows expanded



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?

Returns:

  • (T::Boolean)


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