From ae0b76e6104d79e4e2f03f7f856c97c937f3f9e2 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Wed, 27 May 2020 11:45:55 -0700 Subject: [PATCH] Support imperial units when scaling the unit value We are pretty sure this is not the correct final implementation, but we wanted to get some tests failing so we can start to fix them. --- lib/open_food_network/option_value_namer.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/open_food_network/option_value_namer.rb b/lib/open_food_network/option_value_namer.rb index 22ef439fc4..896412856a 100644 --- a/lib/open_food_network/option_value_namer.rb +++ b/lib/open_food_network/option_value_namer.rb @@ -63,9 +63,15 @@ module OpenFoodNetwork end def scale_for_unit_value - # We're not entirely sure what this is connected to either. - # TODO: DELETE THIS - units = { 'weight' => { 1.0 => 'g', 1000.0 => 'kg', 1_000_000.0 => 'T', 1.0 => 'oz' }, + # TODO: We _think_ this will cause the following weird results: + # 29g of product would use the `oz` measurement + # 445g of product would use the `lb` measurement + # So we probably want to keep the metric and imperial measures + # in their own lanes; perhaps using a configurable value on a per + # shop or producer basis? + + units = { 'weight' => { 1.0 => 'g', 1000.0 => 'kg', 1_000_000.0 => 'T', + 28.34952 => 'oz', 453.59237 => 'lb'}, 'volume' => { 0.001 => 'mL', 1.0 => 'L', 1000.0 => 'kL' } } # Find the largest available unit where unit_value comes to >= 1 when expressed in it.