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.
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/liquid/standardfilters.rb', line 1047 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
1087 1088 1089 |
# File 'lib/liquid/standardfilters.rb', line 1087 def compact to_a.compact end |
#concat(args) ⇒ Object
1075 1076 1077 |
# File 'lib/liquid/standardfilters.rb', line 1075 def concat(args) to_a.concat(args) end |
#each ⇒ Object
1096 1097 1098 1099 1100 1101 1102 |
# File 'lib/liquid/standardfilters.rb', line 1096 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
1091 1092 1093 1094 |
# File 'lib/liquid/standardfilters.rb', line 1091 def empty? @input.each { return false } true end |
#join(glue) ⇒ Object
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# File 'lib/liquid/standardfilters.rb', line 1060 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
1079 1080 1081 |
# File 'lib/liquid/standardfilters.rb', line 1079 def reverse reverse_each.to_a end |
#uniq(&block) ⇒ Object
1083 1084 1085 |
# File 'lib/liquid/standardfilters.rb', line 1083 def uniq(&block) to_a.uniq(&block) end |