Add max/min filters

This commit is contained in:
Nithin Bekal
2017-11-30 13:56:37 -05:00
parent 85b1e91aed
commit 4bdaaf069f
2 changed files with 38 additions and 0 deletions
+16
View File
@@ -355,6 +355,22 @@ module Liquid
raise Liquid::FloatDomainError, e.message
end
def max(input, n)
max_value = Utils.to_number(n)
result = Utils.to_number(input)
result = max_value if result > max_value
result.is_a?(BigDecimal) ? result.to_f : result
end
def min(input, n)
min_value = Utils.to_number(n)
result = Utils.to_number(input)
result = min_value if result < min_value
result.is_a?(BigDecimal) ? result.to_f : result
end
def default(input, default_value = ''.freeze)
if !input || input.respond_to?(:empty?) && input.empty?
default_value