Class: Soroban::LabelWalker

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/soroban/label_walker.rb

Overview

An enumerable that allows the labels for cells in a range to be visited.

Instance Method Summary (collapse)

Constructor Details

- (LabelWalker) initialize(range)

Create a new walker from a supplied range.



10
11
12
# File 'lib/soroban/label_walker.rb', line 10

def initialize(range)
  @_fc, @_fr, @_tc, @_tr = Soroban::Helpers.getRange(range)
end

Instance Method Details

- (Object) each

Yield the label of each cell referenced by the supplied range. For a range of the form “A1:B4”, this will yield “A1”, “A2”, “A3”, …, “B3”, “B4”.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/soroban/label_walker.rb', line 16

def each
  col, row = @_fc, @_fr
  while true do
    yield "#{col}#{row}"
    break if row == @_tr && col == @_tc
    if row == @_tr
      row = @_fr
      col = col.next
    else
      row = row.next
    end
  end
end