Sha256: cf14febf469f5b4cc3a4c3b1b0f9bb0d7c27cf82078539a43edcdce29b35e118

Contents?: true

Size: 605 Bytes

Versions: 6

Compression:

Stored size: 605 Bytes

Contents

module Soroban

  # An enumerable that allows cells in a range to be visited.
  class LabelWalker

    include Enumerable

    # Create a new walker from a supplied range.
    def initialize(range)
      @fc, @fr, @tc, @tr = Soroban::getRange(range)
    end

    # Yield the label of each cell referenced by the supplied range.
    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

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
soroban-0.7.3 lib/soroban/label_walker.rb
soroban-0.7.2 lib/soroban/label_walker.rb
soroban-0.5.4 lib/soroban/label_walker.rb
soroban-0.4.0 lib/soroban/label_walker.rb
soroban-0.3.1 lib/soroban/label_walker.rb
soroban-0.3.0 lib/soroban/label_walker.rb