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.
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/liquid/standardfilters.rb', line 1027 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
1067 1068 1069 |
# File 'lib/liquid/standardfilters.rb', line 1067 def compact to_a.compact end |
#concat(args) ⇒ Object
1055 1056 1057 |
# File 'lib/liquid/standardfilters.rb', line 1055 def concat(args) to_a.concat(args) end |
#each ⇒ Object
1076 1077 1078 1079 1080 1081 1082 |
# File 'lib/liquid/standardfilters.rb', line 1076 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
1071 1072 1073 1074 |
# File 'lib/liquid/standardfilters.rb', line 1071 def empty? @input.each { return false } true end |
#join(glue) ⇒ Object
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/liquid/standardfilters.rb', line 1040 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
1059 1060 1061 |
# File 'lib/liquid/standardfilters.rb', line 1059 def reverse reverse_each.to_a end |
#uniq(&block) ⇒ Object
1063 1064 1065 |
# File 'lib/liquid/standardfilters.rb', line 1063 def uniq(&block) to_a.uniq(&block) end |