molybdenum-99 / reality

Comprehensive data proxy to knowledge about real world
MIT License
817 stars 43 forks source link

For Measure the gem Unitwise could be very efficient. #64

Closed phlegx closed 8 years ago

phlegx commented 8 years ago

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>
zverok commented 8 years ago

Yes, we are aware of Unitwise (and it is already mentioned in https://github.com/molybdenum-99/reality/issues/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.