Shopify / measured

Encapsulate measurements and their units in Ruby and Ruby on Rails.
MIT License
337 stars 28 forks source link

Add support for more weights and masses #89

Closed kirinrastogi closed 7 years ago

kirinrastogi commented 7 years ago

Units added

To consider

I assumed gravity to be 9.80665 m/s2 Calculations are now correct.

Misc

@thegedge This is my first substantial PR to an open source project so I would very much appreciate some feedback, and I'll be quick to fix it on my fork.

part of #84

kirinrastogi commented 7 years ago

@thegedge I added long_ton, short_ton and remove tonne as it is just a Megagram that we can alias later with si_unit. I updated the original description of the pr as well.

I wasn't sure how many aliases we wanted to add, we could also add longton, longtons

kirinrastogi commented 7 years ago

@thegedge I added the aliases you requested, and readded metric tonnes. One thing I noticed is that I am not testing on aliases, does this matter?

Also, the test

test ".convert_to from t to N" do
  assert_conversion Measured::Weight, "2000 t", "19613300 N"
end

fails for all versions except 2.4.0, so I am currently looking into that, I have temporarily removed it as it's inverse works properly.

for all versions besides 2.4.0, the following passes:

test ".convert_to from t to N" do
  assert_conversion Measured::Weight, "2000 t", "19613299 N"
end

they are different by 1. It seems to be some sort of rounding error, with smaller values they are different by 1/3. Could this be related to #64 ? I'm just speculating

kirinrastogi commented 7 years ago

@thegedge done! Let me know if anything looks off, I had trouble resyncing my fork