From 147d7ae24d1df4eb7659453e6b27d29e7d0e09c2 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Wed, 6 Dec 2017 09:48:30 -0500 Subject: [PATCH] Rename min/max filters for clarity --- lib/liquid/standardfilters.rb | 20 +++++++-------- test/integration/standard_filter_test.rb | 32 ++++++++++++------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index e8b19e0..c5dbcb8 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -353,19 +353,19 @@ 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 max_value > result - result.is_a?(BigDecimal) ? result.to_f : result - end - - def min(input, n) + def at_least(input, n) min_value = Utils.to_number(n) result = Utils.to_number(input) - result = min_value if min_value < result + result = min_value if min_value > result + result.is_a?(BigDecimal) ? result.to_f : result + end + + def at_most(input, n) + max_value = Utils.to_number(n) + + result = Utils.to_number(input) + result = max_value if max_value < result result.is_a?(BigDecimal) ? result.to_f : result end diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index d3b64f9..d39472e 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -496,26 +496,26 @@ class StandardFiltersTest < Minitest::Test assert_template_result "5", "{{ price | floor }}", 'price' => NumberLikeThing.new(5.4) end - def test_min - assert_template_result "4", "{{ 5 | min:4 }}" - assert_template_result "5", "{{ 5 | min:5 }}" - assert_template_result "5", "{{ 5 | min:6 }}" + def test_at_most + assert_template_result "4", "{{ 5 | at_most:4 }}" + assert_template_result "5", "{{ 5 | at_most:5 }}" + assert_template_result "5", "{{ 5 | at_most:6 }}" - assert_template_result "4.5", "{{ 4.5 | min:5 }}" - assert_template_result "5", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(6) - assert_template_result "4", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(4) - assert_template_result "4", "{{ 5 | min: width }}", 'width' => NumberLikeThing.new(4) + assert_template_result "4.5", "{{ 4.5 | at_most:5 }}" + assert_template_result "5", "{{ width | at_most:5 }}", 'width' => NumberLikeThing.new(6) + assert_template_result "4", "{{ width | at_most:5 }}", 'width' => NumberLikeThing.new(4) + assert_template_result "4", "{{ 5 | at_most: width }}", 'width' => NumberLikeThing.new(4) end - def test_max - assert_template_result "5", "{{ 5 | max:4 }}" - assert_template_result "5", "{{ 5 | max:5 }}" - assert_template_result "6", "{{ 5 | max:6 }}" + def test_at_least + assert_template_result "5", "{{ 5 | at_least:4 }}" + assert_template_result "5", "{{ 5 | at_least:5 }}" + assert_template_result "6", "{{ 5 | at_least:6 }}" - assert_template_result "5", "{{ 4.5 | max:5 }}" - assert_template_result "6", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(6) - assert_template_result "5", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(4) - assert_template_result "6", "{{ 5 | max: width }}", 'width' => NumberLikeThing.new(6) + assert_template_result "5", "{{ 4.5 | at_least:5 }}" + assert_template_result "6", "{{ width | at_least:5 }}", 'width' => NumberLikeThing.new(6) + assert_template_result "5", "{{ width | at_least:5 }}", 'width' => NumberLikeThing.new(4) + assert_template_result "6", "{{ 5 | at_least: width }}", 'width' => NumberLikeThing.new(6) end def test_append