molybdenum-99/reality

For Measure the gem Unitwise could be very efficient.

phlegx opened this issue · 1 comments

See https://github.com/joshwlewis/unitwise

Here some examples:

require 'unitwise'

distance = Unitwise(0.25, 'mile')   # => #<Unitwise::Measurement value=0.25 unit=mile>
time     = Unitwise(10,   'second') # => #<Unitwise::Measurement value=10 unit=second>
mass     = Unitwise(2800, 'pound')  # => #<Unitwise::Measurement value=2800 unit=pound>

acceleration = 2.0 * distance / time ** 2
# => #<Unitwise::Measurement value=0.005 unit=[mi_us]/s2>

force = (mass * acceleration).to_lbf
# => #<Unitwise::Measurement value=2297.5084316991147 unit=lbf>

power = (force * distance / time).to_horsepower
# => #<Unitwise::Measurement value=551.4031264140402 unit=horsepower>

speed = ((2.0 * acceleration * distance) ** 0.5).convert_to("mile/hour")
# => #<Unitwise::Measurement value=180.0 unit=mile/hour>

Unitwise(20, 'milligram') / Unitwise(1, 'liter')
# => #<Unitwise::Measurement value=20 unit=mg/l>

Yes, we are aware of Unitwise (and it is already mentioned in #11).

But in fact it is not quite suiting our needs, due to some "mental model incompatibility" problems, like described here (second part of a ticket) or there (also second part of a ticket). So, I think Reality::Measure may be using Unitwise under the hoods in future, but it is unlike to be completely replaced.