summaryrefslogtreecommitdiff
path: root/fake-service/lib/pixelated_service/paginated_enumerable.rb
blob: b1045e2ffa494cf8bcc1790f0f6dec549a3054ea (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

module PixelatedService
  class Paginate
    class PaginatedEnumerable
      include Enumerable
      def initialize(input, start, e)
        @input = input
        @start = start
        @end = e
      end

      def each
        @input.each_with_index do |v, ix|
          if ix >= @end
            return #we are done
          elsif ix >= @start
            yield v
          end
        end
      end

      def each_total
        @input.each do |v|
          yield v
        end
      end
    end
  end
end