summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/tablerowloop_drop.rb
blob: cda4a1ed43efca216d9cba79a890ae2f0a485e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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