Sha256: 5df355139f13e0080b4d0b9e705670d56058f15c8c6a5979408ccffdbd5dd05f

Contents?: true

Size: 815 Bytes

Versions: 5

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

module Liquid
  class TablerowloopDrop < Drop
    def initialize(length, cols)
      @length = length
      @row    = 1
      @col    = 1
      @cols   = cols
      @index  = 0
    end

    attr_reader :length, :col, :row

    def index
      @index + 1
    end

    def index0
      @index
    end

    def col0
      @col - 1
    end

    def rindex
      @length - @index
    end

    def rindex0
      @length - @index - 1
    end

    def first
      @index == 0
    end

    def last
      @index == @length - 1
    end

    def col_first
      @col == 1
    end

    def col_last
      @col == @cols
    end

    protected

    def increment!
      @index += 1

      if @col == @cols
        @col = 1
        @row += 1
      else
        @col += 1
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
liquid-5.3.0 lib/liquid/tablerowloop_drop.rb
liquid-5.2.0 lib/liquid/tablerowloop_drop.rb
liquid-5.1.0 lib/liquid/tablerowloop_drop.rb
liquid-5.0.1 lib/liquid/tablerowloop_drop.rb
liquid-5.0.0 lib/liquid/tablerowloop_drop.rb