class Liquid::StandardFilters::InputIterator

Public Class Methods

new(input) click to toggle source
# File lib/liquid/standardfilters.rb, line 421
def initialize(input)
  @input = if input.is_a?(Array)
    input.flatten
  elsif input.is_a?(Hash)
    [input]
  elsif input.is_a?(Enumerable)
    input
  else
    Array(input)
  end
end

Public Instance Methods

compact() click to toggle source
# File lib/liquid/standardfilters.rb, line 449
def compact
  to_a.compact
end
concat(args) click to toggle source
# File lib/liquid/standardfilters.rb, line 437
def concat(args)
  to_a.concat(args)
end
each() { |respond_to?(:to_liquid) ? to_liquid : e| ... } click to toggle source
# File lib/liquid/standardfilters.rb, line 458
def each
  @input.each do |e|
    yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)
  end
end
empty?() click to toggle source
# File lib/liquid/standardfilters.rb, line 453
def empty?
  @input.each { return false }
  true
end
join(glue) click to toggle source
# File lib/liquid/standardfilters.rb, line 433
def join(glue)
  to_a.join(glue.to_s)
end
reverse() click to toggle source
# File lib/liquid/standardfilters.rb, line 441
def reverse
  reverse_each.to_a
end
uniq(&block) click to toggle source
# File lib/liquid/standardfilters.rb, line 445
def uniq(&block)
  to_a.uniq(&block)
end
where(property, target_value) click to toggle source
# File lib/liquid/standardfilters.rb, line 464
def where(property, target_value)
  select do |item|
    item[property] == target_value
  end
rescue TypeError
  # Cannot index with the given property type (eg. indexing integers with strings
  # which are only allowed to be indexed by other integers).
  raise ArgumentError.new("cannot select the property `#{property}`")
end
where_present(property) click to toggle source
# File lib/liquid/standardfilters.rb, line 474
def where_present(property)
  select { |item| item[property] }
rescue TypeError
  # Cannot index with the given property type (eg. indexing integers with strings
  # which are only allowed to be indexed by other integers).
  raise ArgumentError.new("cannot select the property `#{property}`")
end