use ruby-units for unit parsing (closes foodcoops/foodsoft#200)
Conflicts: Gemfile Gemfile.lock
This commit is contained in:
parent
48e9a3e4f5
commit
c25d4d3f4f
5 changed files with 48 additions and 23 deletions
|
|
@ -91,22 +91,6 @@ default: &defaults
|
|||
encoding: utf8
|
||||
socket: /opt/lampp/var/mysql/mysql.sock
|
||||
|
||||
# auto-units-conversion
|
||||
# this is used for automatic article-synchronization to handle different units
|
||||
# e.g. when foodcoop-unit should be 500g and supplier-unit is 1kg
|
||||
units:
|
||||
KG: 1
|
||||
1kg: 1
|
||||
500g: 0.5
|
||||
400g: 0.4
|
||||
300g: 0.3
|
||||
250g: 0.25
|
||||
200g: 0.2
|
||||
150g: 0.15
|
||||
125g: 0.125
|
||||
100g: 0.1
|
||||
50g: 0.05
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
||||
|
|
|
|||
37
config/initializers/ruby_units.rb
Normal file
37
config/initializers/ruby_units.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# add some more units
|
||||
|
||||
if defined? RubyUnits
|
||||
RubyUnits::Unit.redefine!('liter') do |unit|
|
||||
unit.aliases += %w{ltr}
|
||||
end
|
||||
|
||||
RubyUnits::Unit.redefine!('kilogram') do |unit|
|
||||
unit.aliases += %w{KG}
|
||||
end
|
||||
|
||||
RubyUnits::Unit.redefine!('gram') do |unit|
|
||||
unit.aliases += %w{gr}
|
||||
end
|
||||
|
||||
RubyUnits::Unit.define('piece') do |unit|
|
||||
unit.definition = RubyUnits::Unit.new('1 each')
|
||||
unit.aliases = %w{pc pcs piece pieces} # locale: en
|
||||
unit.aliases += %w{st stuk stuks} # locale: nl
|
||||
unit.kind = :counting
|
||||
end
|
||||
|
||||
# we use pc for piece, not parsec
|
||||
RubyUnits::Unit.redefine!('parsec') do |unit|
|
||||
unit.aliases = unit.aliases.reject {|u| u=='pc'}
|
||||
unit.display_name = 'parsec'
|
||||
end
|
||||
|
||||
# workaround for ruby-units' require mathn warning: "zero and implicit precision is deprecated."
|
||||
# default precision of 8 which same as all database definitions in db/migrate/20131213002332_*.rb
|
||||
class Rational
|
||||
alias orig_to_d to_d
|
||||
def to_d(precision=8)
|
||||
orig_to_d(precision)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue