summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/liquid-4.0.4/lib/liquid/forloop_drop.rb
blob: 81b2d1a281337bda56115b9127a23e0baf36aa68 (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
module Liquid
  class ForloopDrop < Drop
    def initialize(name, length, parentloop)
      @name = name
      @length = length
      @parentloop = parentloop
      @index = 0
    end

    attr_reader :name, :length, :parentloop

    def index
      @index + 1
    end

    def index0
      @index
    end

    def rindex
      @length - @index
    end

    def rindex0
      @length - @index - 1
    end

    def first
      @index == 0
    end

    def last
      @index == @length - 1
    end

    protected

    def increment!
      @index += 1
    end
  end
end