Sha256: ec197f13821dd8e7f1a66af0111052818543f1969b2b264761039434ed1ead85

Contents?: true

Size: 569 Bytes

Versions: 7

Compression:

Stored size: 569 Bytes

Contents

module Liquid
  module Utils
    def self.slice_collection_using_each(collection, from, to)
      segments = []
      index = 0

      # Maintains Ruby 1.8.7 String#each behaviour on 1.9
      return [collection] if non_blank_string?(collection)

      collection.each do |item|

        if to && to <= index
          break
        end

        if from <= index
          segments << item
        end

        index += 1
      end

      segments
    end

    def self.non_blank_string?(collection)
      collection.is_a?(String) && collection != ''
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
liquid-2.6.3 lib/liquid/utils.rb
liquid-2.6.2 lib/liquid/utils.rb
liquid-2.6.1 lib/liquid/utils.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/liquid-2.6.0/lib/liquid/utils.rb
liquid-2.6.0 lib/liquid/utils.rb
liquid-2.6.0.rc1 lib/liquid/utils.rb
locomotivecms-liquid-2.6.0 lib/liquid/utils.rb