lib/unit_measurements/measurement.rb in unit_measurements-1.0.0 vs lib/unit_measurements/measurement.rb in unit_measurements-1.1.0
- old
+ new
@@ -2,16 +2,17 @@
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-
module UnitMeasurements
class Measurement
+ include Formatter
CONVERSION_STRING_REGEXP = /(.+?)\s?(?:\s+(?:in|to|as)\s+(.+)|\z)/i.freeze
attr_reader :quantity, :unit
def initialize(quantity, unit)
- raise ArgumentError, "Quantity cannot be blank." if quantity.blank?
- raise ArgumentError, "Unit cannot be blank." if unit.blank?
+ raise BaseError, "Quantity cannot be blank." if quantity.blank?
+ raise BaseError, "Unit cannot be blank." if unit.blank?
@quantity = convert_quantity(quantity)
@unit = unit_from_unit_or_name!(unit)
end