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) ⇒ InputIterator
constructor
A new instance of InputIterator.
- #join(glue) ⇒ Object
- #reverse ⇒ Object
- #uniq(&block) ⇒ Object
- #where(property, target_value) ⇒ Object
- #where_present(property) ⇒ Object
Constructor Details
#initialize(input) ⇒ InputIterator
Returns a new instance of InputIterator.
421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/liquid/standardfilters.rb', line 421 def initialize(input) @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
449 450 451 |
# File 'lib/liquid/standardfilters.rb', line 449 def compact to_a.compact end |
#concat(args) ⇒ Object
437 438 439 |
# File 'lib/liquid/standardfilters.rb', line 437 def concat(args) to_a.concat(args) end |
#each ⇒ Object
458 459 460 461 462 |
# File 'lib/liquid/standardfilters.rb', line 458 def each @input.each do |e| yield(e.respond_to?(:to_liquid) ? e.to_liquid : e) end end |
#empty? ⇒ Boolean
453 454 455 456 |
# File 'lib/liquid/standardfilters.rb', line 453 def empty? @input.each { return false } true end |
#join(glue) ⇒ Object
433 434 435 |
# File 'lib/liquid/standardfilters.rb', line 433 def join(glue) to_a.join(glue.to_s) end |
#reverse ⇒ Object
441 442 443 |
# File 'lib/liquid/standardfilters.rb', line 441 def reverse reverse_each.to_a end |
#uniq(&block) ⇒ Object
445 446 447 |
# File 'lib/liquid/standardfilters.rb', line 445 def uniq(&block) to_a.uniq(&block) end |
#where(property, target_value) ⇒ Object
464 465 466 467 468 469 470 471 472 |
# File 'lib/liquid/standardfilters.rb', line 464 def where(property, target_value) select do |item| item[property] == target_value end rescue TypeError # Cannot index with the given property type (eg. indexing integers with strings # which are only allowed to be indexed by other integers). raise ArgumentError.new("cannot select the property `#{property}`") end |
#where_present(property) ⇒ Object
474 475 476 477 478 479 480 |
# File 'lib/liquid/standardfilters.rb', line 474 def where_present(property) select { |item| item[property] } rescue TypeError # Cannot index with the given property type (eg. indexing integers with strings # which are only allowed to be indexed by other integers). raise ArgumentError.new("cannot select the property `#{property}`") end |