lib/conversions/unit.rb in seamusabshere-conversions-1.2.1 vs lib/conversions/unit.rb in seamusabshere-conversions-1.2.2
- old
+ new
@@ -27,20 +27,30 @@
raise ArgumentError, "Can't convert from `#{from_unit}' to `#{to_unit}', unknown unit" if to.nil?
to
end
def self.conversion #:nodoc:
- if !defined? @@conversion
- @@conversion = {}
- CONVERSION.each do |from, conversion|
- conversion.each do |to, value|
- @@conversion[from] ||= {}
- @@conversion[from][to] = value
- @@conversion[to] ||= {}
- @@conversion[to][from] = 1.0 / value
- end
+ map_conversion if !defined? @@conversion
+ @@conversion
+ end
+
+ def self.register(from, to, value)
+ CONVERSION.merge!(from.to_sym => { to.to_sym => value.to_f })
+ map_conversion
+ Numeric.send :include, Conversions::Ext
+ end
+
+ private
+
+ def self.map_conversion
+ @@conversion = {}
+ CONVERSION.each do |from, conversion|
+ conversion.each do |to, value|
+ @@conversion[from] ||= {}
+ @@conversion[from][to] = value
+ @@conversion[to] ||= {}
+ @@conversion[to][from] = 1.0 / value
end
end
- @@conversion
end
end
end