Compare commits

..
Author SHA1 Message Date
Melanie Wang 2bcecf0556 Document math filters 2022-03-14 13:51:07 -04:00
+16 -24
View File
@@ -298,12 +298,7 @@ module Liquid
end
end
# @public_docs
# @syntax {{ string | replace: string, substring }}
# @summary Replaces all occurrences of a string with a substring.
# @type filter
# @category string
# @return string
# Replace occurrences of a string with another
def replace(input, string, replacement = '')
input.to_s.gsub(string.to_s, replacement.to_s)
end
@@ -328,22 +323,12 @@ module Liquid
output
end
# @public_docs
# @syntax {{ string | remove: string }}
# @summary Removes a substring.
# @type filter
# @category string
# @return string
# remove a substring
def remove(input, string)
replace(input, string, '')
end
# @public_docs
# @syntax {{ string | remove_first: string }}
# @summary Removes the first occurrences of a substring.
# @type filter
# @category string
# @return string
# remove the first occurrences of a substring
def remove_first(input, string)
replace_first(input, string, '')
end
@@ -365,12 +350,7 @@ module Liquid
InputIterator.new(input, context).concat(array)
end
# @public_docs
# @syntax {{ string | prepend: string }}
# @summary Prepend a string to another string.
# @type filter
# @category string
# @return string
# prepend a string to another
def prepend(input, string)
string.to_s + input.to_s
end
@@ -492,6 +472,12 @@ module Liquid
raise Liquid::FloatDomainError, e.message
end
# @public_docs
# @syntax {{ number | at_least: number }}
# @summary Limits a number to a minimum value.
# @type filter
# @category Math
# @return number
def at_least(input, n)
min_value = Utils.to_number(n)
@@ -500,6 +486,12 @@ module Liquid
result.is_a?(BigDecimal) ? result.to_f : result
end
# @public_docs
# @syntax {{ number | at_most: number }}
# @summary Limits a number to a maximum value.
# @type filter
# @category Math
# @return number
def at_most(input, n)
max_value = Utils.to_number(n)