lib/unit_measurements/measurement.rb in unit_measurements-3.8.0 vs lib/unit_measurements/measurement.rb in unit_measurements-4.0.0

- old
+ new

@@ -29,28 +29,22 @@ conversion_factor = (unit.conversion_factor / target_unit.conversion_factor) self.class.new((quantity * conversion_factor), target_unit) end - alias_method :to, :convert_to - alias_method :in, :convert_to - alias_method :as, :convert_to + [:to, :in, :as].each { |method_alias| alias_method method_alias, :convert_to } def convert_to!(target_unit) measurement = convert_to(target_unit) @quantity, @unit = measurement.quantity, measurement.unit self end - alias_method :to!, :convert_to! - alias_method :in!, :convert_to! - alias_method :as!, :convert_to! + [:to!, :in!, :as!].each { |method_alias| alias_method method_alias, :convert_to! } def inspect(dump: false) - return super() if dump - - to_s + dump ? super() : to_s end def to_s "#{quantity} #{unit}" end @@ -69,12 +63,12 @@ def unit_group raise BaseError, "`Measurement` does not have a `unit_group` object. You cannot directly use `Measurement`. Instead, build a new unit group by calling `UnitMeasurements.build`." end - def_delegators :unit_group, :units, :unit_names, :unit_with_name_and_aliases, + def_delegators :unit_group, :primitive, :units, :unit_names, :unit_with_name_and_aliases, :unit_names_with_aliases, :unit_for, :unit_for!, :defined?, - :unit_or_alias?, :[], :systems, :system_for + :unit_or_alias?, :[] def parse(input) input = Normalizer.normalize(input) source, target = input.match(CONVERSION_STRING_REGEXP)&.captures