Merge pull request #4895 from Growstuff/replace-ruby-units

Remove ruby-units gem and implement weight unit
This commit is contained in:
Brenda Wallace authored and GitHub committed 2026-10-11 21:44:40 +13:00
commit ff03583e75
3 files changed
+8 -5

No files matched your search

-1
View File
@@ -58,7 +58,6 @@ gem 'gibbon', '~>1.2.0' # for Mailchimp newsletter subscriptions
gem 'leaflet-rails', '>= 1.9.2'
gem 'pg'
gem 'ruby-units' # for unit conversion
gem "comfortable_mexican_sofa", git: "https://github.com/restarone/comfortable-mexican-sofa.git"
-2
View File
@@ -660,7 +660,6 @@ GEM
rubocop (~> 1.72, >= 1.72.1)
rubocop-rspec (~> 3.5)
ruby-progressbar (1.13.0)
ruby-units (4.1.0)
ruby-vips (2.3.0)
ffi (~> 1.12)
logger
@@ -851,7 +850,6 @@ DEPENDENCIES
rubocop-rake
rubocop-rspec
rubocop-rspec_rails
ruby-units
sassc-rails
scout_apm
searchkick
+8 -2
View File
@@ -31,6 +31,13 @@ class Harvest < ApplicationRecord
"oz" => "oz"
}.freeze
# Exact definitions of the international avoirdupois units, in kilograms.
KG_PER_WEIGHT_UNIT = {
"kg" => BigDecimal("1"),
"lb" => BigDecimal("0.45359237"),
"oz" => BigDecimal("0.028349523125")
}.freeze
##
## Triggers
after_validation :cleanup_quantities
@@ -91,8 +98,7 @@ class Harvest < ApplicationRecord
def set_si_weight
return if weight_unit.nil?
weight_string = "#{weight_quantity} #{weight_unit}"
self.si_weight = Unit.new(weight_string).convert_to("kg").to_s("%0.3f").delete(" kg").to_f
self.si_weight = (weight_quantity * KG_PER_WEIGHT_UNIT.fetch(weight_unit)).round(3).to_f
end
def cleanup_quantities