Class: Liquid::StandardFilters::InputIterator
- Inherits:
-
Object
- Object
- Liquid::StandardFilters::InputIterator
- Includes:
- Enumerable
- Defined in:
- lib/liquid/standardfilters.rb
Instance Method Summary collapse
- #compact ⇒ Object
- #concat(args) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(input, context) ⇒ InputIterator
constructor
A new instance of InputIterator.
- #join(glue) ⇒ Object
- #reverse ⇒ Object
- #uniq(&block) ⇒ Object
Constructor Details
#initialize(input, context) ⇒ InputIterator
Returns a new instance of InputIterator.
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'lib/liquid/standardfilters.rb', line 1045 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
#compact ⇒ Object
1085 1086 1087 |
# File 'lib/liquid/standardfilters.rb', line 1085 def compact to_a.compact end |
#concat(args) ⇒ Object
1073 1074 1075 |
# File 'lib/liquid/standardfilters.rb', line 1073 def concat(args) to_a.concat(args) end |
#each ⇒ Object
1094 1095 1096 1097 1098 1099 1100 |
# File 'lib/liquid/standardfilters.rb', line 1094 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
1089 1090 1091 1092 |
# File 'lib/liquid/standardfilters.rb', line 1089 def empty? @input.each { return false } true end |
#join(glue) ⇒ Object
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/liquid/standardfilters.rb', line 1058 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 |
#reverse ⇒ Object
1077 1078 1079 |
# File 'lib/liquid/standardfilters.rb', line 1077 def reverse reverse_each.to_a end |
#uniq(&block) ⇒ Object
1081 1082 1083 |
# File 'lib/liquid/standardfilters.rb', line 1081 def uniq(&block) to_a.uniq(&block) end |