Sha256: 4727aba6db57ed5499e7b1042c772865226df23734ae79c3140c9c8cba5358dd

Contents?: true

Size: 587 Bytes

Versions: 10

Compression:

Stored size: 587 Bytes

Contents

module Liquid
  module Utils
    def self.slice_collection_using_each(collection, from, to)
      segments = []
      index = 0
      yielded = 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

10 entries across 10 versions & 3 rubygems

Version Path
liquid-2.5.5 lib/liquid/utils.rb
liquid-2.5.4 lib/liquid/utils.rb
liquid-2.5.3 lib/liquid/utils.rb
liquid-2.5.1 lib/liquid/utils.rb
wordify_liquid-2.5.1 lib/liquid/utils.rb
liquid-2.5.0 lib/liquid/utils.rb
locomotive_liquid-2.4.2 lib/liquid/utils.rb
locomotive_liquid-2.4.1 lib/liquid/utils.rb
liquid-2.4.1 lib/liquid/utils.rb
liquid-2.4.0 lib/liquid/utils.rb