ruby-units icon indicating copy to clipboard operation
ruby-units copied to clipboard

Add support for <unit> per N <unit>

Open stwr667 opened this issue 4 years ago • 2 comments

E.g. "2 kg/100kg" or "4 l/1000l".

It's similar to a percentage, but can be for any scalar number, and is often the terminology used in industry, rather than percentages. E.g. in Agriculture - adding 4 liters of Roundup per 100 liters of tank mixture.

Example unit definitions:

Unit.define('100kg') do |u|
  u.definition = Unit.new('100 kg')
  u.aliases = %w[100kg]
end

stwr667 avatar Nov 30 '20 06:11 stwr667

Hi @olbrich, we've used a forked version of Ruby-units for a while now, and are trying to get back to master. This PR is my attempt at fixing one of the last divergent behaviours that we have working locally, but cannot get working on the latest master version of ruby-units. I've written specs to show the kind of behaviour we're aiming for. I've fixed a few of them. Although I'm not sure I've gone with the best approach. Multiplying these kinds of units, and adding doesn't quite work, and so I probably haven't set up the base units properly. If you have any guidance that would be great! Thanks, Steve.

stwr667 avatar Nov 30 '20 06:11 stwr667

@stwr667 Sorry, I've been a bit slow to respond. I will be updating the gem to make sure ruby support has been updated now that Ruby 3.0 has been released. Once I'm done with that I will be taking a look at any outstanding PRs.

olbrich avatar Dec 26 '20 19:12 olbrich