Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phlegx opened this issue Jun 4, 2016 · 1 comment
Closed

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

phlegx opened this issue Jun 4, 2016 · 1 comment

Comments

@phlegx
Copy link

phlegx commented Jun 4, 2016

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
Copy link
Contributor

zverok commented Jun 6, 2016

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.

@zverok zverok closed this as completed Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants