module Locomotive::Steam::Liquid::Filters::Misc

Public Instance Methods

blank?(input) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 7
def blank?(input)
  input.blank?
end
default(input, value) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 29
def default(input, value)
  input.blank? ? value : input
end
hexdigest(input, key, digest = nil) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 57
def hexdigest(input, key, digest = nil)
  OpenSSL::HMAC.hexdigest(digest || 'sha1', key, input)
end
index(array, position) click to toggle source

Get the nth element of the passed in array

# File lib/locomotive/steam/liquid/filters/misc.rb, line 21
def index(array, position)
  array.at(position) if array.respond_to?(:at)
end
map(input, property) click to toggle source

map/collect on a given property (support to_f, to_i)

# File lib/locomotive/steam/liquid/filters/misc.rb, line 38
def map(input, property)
  ::Liquid::StandardFilters::InputIterator.new(input).map do |e|
    e = e.call if e.is_a?(Proc)

    if property == 'to_liquid'.freeze
      e
    elsif property == 'to_f'.freeze
      e.to_f
    elsif property == 'to_i'.freeze
      e.to_i
    elsif e.respond_to?(:[])
      r = e[property]
      r.is_a?(Proc) ? r.call : r
    end
  end
rescue TypeError
  raise_property_error(property)
end
present?(input) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 11
def present?(input)
  input.present?
end
random(input) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 33
def random(input)
  rand(input.to_i)
end
shuffle(array) click to toggle source
# File lib/locomotive/steam/liquid/filters/misc.rb, line 25
def shuffle(array)
  array.to_a.shuffle
end
str_modulo(word, index, modulo) click to toggle source

was called modulo at first

# File lib/locomotive/steam/liquid/filters/misc.rb, line 16
def str_modulo(word, index, modulo)
  (index.to_i + 1) % modulo == 0 ? word : ''
end