Shopify / measured

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

Only show unit name, adding #humanize for pluralization #77

Closed thegedge closed 7 years ago

thegedge commented 7 years ago

After merging https://github.com/Shopify/measured/pull/72, Unit#to_s now shows its conversion when to_s-ing a Measurable. This is almost always undesirable for presentation, so we should instead just show the unit name.

Since we depend on ActiveSupport I've also added a #humanize method that can pluralize the unit name if the value isn't unity.

thegedge commented 7 years ago

Added additional tests. I also realized, which I should have earlier, that we to_f for Rational output when the denominator isn't 1. This means that pluralizing doesn't read as well (e.g., "1/8 fireball" vs "0.125 fireballs").

thegedge commented 7 years ago

Will switch the merge base and rebase on master once unit-improvements (https://github.com/Shopify/measured/pull/74) reviewed and merged.