README.md in ruby-units-2.0.1 vs README.md in ruby-units-2.1.0
- old
+ new
@@ -116,10 +116,11 @@
Unit.new('1.5 mm').to_s("%0.2f") # "1.50 mm". Enter any valid format
string. Also accepts strftime format
Unit.new('1.5 mm').to_s("in") # converts to inches before printing
Unit.new("2 m").to_s(:ft) # returns 6'7"
Unit.new("100 kg").to_s(:lbs) # returns 220 lbs, 7 oz
+Unit.new("100 kg").to_s(:stone) # returns 15 stone, 10 lb
```
Time Helpers
------------
@@ -226,13 +227,25 @@
Unit.redefine!("cup") do |cup|
cup.display_name = "cup"
end
```
+### Useful methods
+
+1. `scalar` will return the numeric portion of the unit without the attached units
+2. `base_scalar` will return the scalar in base units (SI)
+3. `units` will return the name of the units (without the scalar)
+4. `base` will return the unit converted to base units (SI)
+
+### Storing in a database
+
+Units can be stored in a database as either the string representation or in two separate columns defining the scalar and the units.
+Note that if sorting by units is desired you will want to ensure that you are storing the scalars in a consistent unit (i.e, the base units).
+
### Namespaced Class
-Sometimes the default class 'Unit' may conflict with other gems or applications. Internally ruby-units defines itself using the RubyUnits namespace. The actual class of a unit is the RubyUnits::Unit. For simplicity and backwards compatiblity, the '::Unit' class is defined as an alias to '::RubyUnits::Unit'.
+Sometimes the default class 'Unit' may conflict with other gems or applications. Internally ruby-units defines itself using the RubyUnits namespace. The actual class of a unit is the RubyUnits::Unit. For simplicity and backwards compatibility, the '::Unit' class is defined as an alias to '::RubyUnits::Unit'.
To load ruby-units without this alias...
```
require 'ruby_units/namespaced'
@@ -243,5 +256,39 @@
```
gem 'ruby-units', require: 'ruby_units/namespaced'
```
Note: when using the namespaced version, the Unit.new('unit string') helper will not be defined.
+
+### Configuration
+
+Configuration options can be set like:
+
+```
+RubyUnits.configure do |config|
+ config.separator = false
+end
+```
+
+Currently there is only one configuration you can set:
+
+1. separator (true/false): should a space be used to separate the scalar from the unit part during output.
+
+
+### NOTES
+
+#### Mathn
+
+Note that the current implementation of ruby-units requires 'mathn' from the ruby standard library.
+This tends to change the behavior of integer math in ways that many people do not expect, and can be the source
+of numerous bugs and odd behaviors. If you encounter what appears to be a bug in your code that seems to be related
+
+to the use of ruby-units, try to reproduce the bug by just including 'mathn' by itself.
+
+If you identify a bug in a gem or code that uses mathn, please file a bug report or create a pull request to fix it.
+
+#### Performance vs. Accuracy
+
+Ruby units was originally intended to provide a robust and accurate way to do arbitrary unit conversions.
+In some cases, these conversions can result in the creation and garbage collection of a lot of intermediate objects during
+calculations. This in turn can have a negative impact on performance. The design of ruby-units has emphasized accuracy
+over speed. YMMV if you are doing a lot of math involving units.