Module: Locomotive::Steam::Liquid::Filters::Misc
- Defined in:
- lib/locomotive/steam/liquid/filters/misc.rb
Instance Method Summary collapse
- #blank?(input) ⇒ Boolean
- #default(input, value) ⇒ Object
- #hexdigest(input, key, digest = nil) ⇒ Object
-
#index(array, position) ⇒ Object
Get the nth element of the passed in array.
-
#map(input, property) ⇒ Object
map/collect on a given property (support to_f, to_i).
- #present?(input) ⇒ Boolean
- #random(input) ⇒ Object
- #shuffle(array) ⇒ Object
-
#str_modulo(word, index, modulo) ⇒ Object
was called modulo at first.
Instance Method Details
#blank?(input) ⇒ Boolean
7 8 9 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 7 def blank?(input) input.blank? end |
#default(input, value) ⇒ Object
29 30 31 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 29 def default(input, value) input.blank? ? value : input end |
#hexdigest(input, key, digest = nil) ⇒ Object
57 58 59 |
# 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) ⇒ Object
Get the nth element of the passed in array
21 22 23 |
# 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) ⇒ Object
map/collect on a given property (support to_f, to_i)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Boolean
11 12 13 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 11 def present?(input) input.present? end |
#random(input) ⇒ Object
33 34 35 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 33 def random(input) rand(input.to_i) end |
#shuffle(array) ⇒ Object
25 26 27 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 25 def shuffle(array) array.to_a.shuffle end |
#str_modulo(word, index, modulo) ⇒ Object
was called modulo at first
16 17 18 |
# File 'lib/locomotive/steam/liquid/filters/misc.rb', line 16 def str_modulo(word, index, modulo) (index.to_i + 1) % modulo == 0 ? word : '' end |