Sha256: 2565cfa4aa9e1c923ea98c89a8fdddec7121d3617527586483d8470ee5c2a1e8

Contents?: true

Size: 780 Bytes

Versions: 14

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

class ActiveSet
  module Paginating
    class EnumerableStrategy
      def initialize(set, operation_instructions)
        @set = set
        @operation_instructions = operation_instructions
      end

      def execute
        return [] if @set.count <= @operation_instructions[:size] &&
                     @operation_instructions[:page] > 1

        @set[page_start..page_end] || []
      end

      private

      def page_start
        return 0 if @operation_instructions[:page] == 1

        @operation_instructions[:size] * (@operation_instructions[:page] - 1)
      end

      def page_end
        return page_start if @operation_instructions[:size] == 1

        page_start + @operation_instructions[:size] - 1
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
actionset-0.11.0 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.10.0 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.9.2 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.9.1 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.8.2 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.8.1 lib/active_set/paginating/enumerable_strategy.rb
actionset-0.8.0 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.6 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.5 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.4 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.3 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.2 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.1 lib/active_set/paginating/enumerable_strategy.rb
activeset-0.8.0 lib/active_set/paginating/enumerable_strategy.rb