Re-arrange imperial units

Who would have guessed it was this complicated.

Fingers crossed this doesn't break any other functionality...
This commit is contained in:
David Cook
2024-02-21 15:18:42 +11:00
parent ea0067946d
commit 2ef9e34f28
2 changed files with 15 additions and 5 deletions

View File

@@ -45,9 +45,16 @@ class WeightsAndMeasures
def self.available_units_sorted
self::UNITS.transform_values do |measurement_info|
# Filter to only include available units
measurement_info.filter do |_scale, unit_info|
available_units.include?(unit_info['name'])
end.sort.to_h # sort by unit (hash key)
end.
# Remove duplicates by name
uniq do |_scale, unit_info|
unit_info['name']
end.
# Sort by unit number
sort.to_h
end
end
@@ -60,10 +67,10 @@ class WeightsAndMeasures
1000.0 => { 'name' => 'kg', 'system' => 'metric' },
1_000_000.0 => { 'name' => 'T', 'system' => 'metric' },
28.349523125 => { 'name' => 'oz', 'system' => 'imperial' },
28.35 => { 'name' => 'oz', 'system' => 'imperial' },
453.59237 => { 'name' => 'lb', 'system' => 'imperial' },
28.349523125 => { 'name' => 'oz', 'system' => 'imperial' },
453.6 => { 'name' => 'lb', 'system' => 'imperial' },
453.59237 => { 'name' => 'lb', 'system' => 'imperial' },
},
'volume' => {
0.001 => { 'name' => 'mL', 'system' => 'metric' },

View File

@@ -30,6 +30,11 @@ describe WeightsAndMeasures do
allow(product).to receive(:variant_unit_scale) { 28.35 }
expect(subject.system).to eq("imperial")
end
it "when precise scale is for an imperial unit" do
allow(product).to receive(:variant_unit_scale) { 28.349523125 }
expect(subject.system).to eq("imperial")
end
end
context "volume" do
@@ -79,7 +84,6 @@ describe WeightsAndMeasures do
["Volume (kL)", "volume_1000"],
["Items", "items"],
]
pending "imperial measurements are duplicated"
expect(subject).to match_array expected_array # diff each element
expect(subject).to eq expected_array # test ordering also
end
@@ -97,7 +101,6 @@ describe WeightsAndMeasures do
["Volume (L)", "volume_1"],
["Items", "items"],
]
pending "imperial measurements are duplicated"
expect(subject).to match_array expected_array # diff each element
expect(subject).to eq expected_array # test ordering also
end