mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-11-06 05:02:50 -05:00
Merge pull request #4895 from Growstuff/replace-ruby-units
Remove ruby-units gem and implement weight unit
This commit is contained in:
3 files changed
+8
-5
No files matched your search
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user