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.
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
# File 'lib/liquid/standardfilters.rb', line 1035 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
1078 1079 1080 |
# File 'lib/liquid/standardfilters.rb', line 1078 def compact to_a.compact end |
#concat(args) ⇒ Object
1063 1064 1065 |
# File 'lib/liquid/standardfilters.rb', line 1063 def concat(args) to_a.concat(args) end |
#each ⇒ Object
1087 1088 1089 1090 1091 1092 1093 |
# File 'lib/liquid/standardfilters.rb', line 1087 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
1082 1083 1084 1085 |
# File 'lib/liquid/standardfilters.rb', line 1082 def empty? @input.each { return false } true end |
#join(glue) ⇒ Object
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
# File 'lib/liquid/standardfilters.rb', line 1048 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
1067 1068 1069 |
# File 'lib/liquid/standardfilters.rb', line 1067 def reverse reverse_each.to_a end |
#uniq(&block) ⇒ Object
1071 1072 1073 1074 1075 1076 |
# File 'lib/liquid/standardfilters.rb', line 1071 def uniq(&block) to_a.uniq do |item| item = Utils.to_liquid_value(item) block ? yield(item) : item end end |