Module: Liquid::Utils

Defined in:
lib/liquid/utils.rb

Class Method Summary collapse

Class Method Details

.non_blank_string?(collection) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/liquid/utils.rb', line 27

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

.slice_collection_using_each(collection, from, to) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/liquid/utils.rb', line 3

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