Class: Liquid::StandardFilters::InputIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/liquid/standardfilters.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, context) ⇒ InputIterator

Returns a new instance of InputIterator.



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'lib/liquid/standardfilters.rb', line 1052

def initialize(input, context)
  @context = context
  @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

Instance Method Details

#compactObject



1092
1093
1094
# File 'lib/liquid/standardfilters.rb', line 1092

def compact
  to_a.compact
end

#concat(args) ⇒ Object



1080
1081
1082
# File 'lib/liquid/standardfilters.rb', line 1080

def concat(args)
  to_a.concat(args)
end

#eachObject



1101
1102
1103
1104
1105
1106
1107
# File 'lib/liquid/standardfilters.rb', line 1101

def each
  @input.each do |e|
    e = e.respond_to?(:to_liquid) ? e.to_liquid : e
    e.context = @context if e.respond_to?(:context=)
    yield(e)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


1096
1097
1098
1099
# File 'lib/liquid/standardfilters.rb', line 1096

def empty?
  @input.each { return false }
  true
end

#join(glue) ⇒ Object



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/liquid/standardfilters.rb', line 1065

def join(glue)
  first = true
  output = +""
  each do |item|
    if first
      first = false
    else
      output << glue
    end

    output << Liquid::Utils.to_s(item)
  end
  output
end

#reverseObject



1084
1085
1086
# File 'lib/liquid/standardfilters.rb', line 1084

def reverse
  reverse_each.to_a
end

#uniq(&block) ⇒ Object



1088
1089
1090
# File 'lib/liquid/standardfilters.rb', line 1088

def uniq(&block)
  to_a.uniq(&block)
end