diff --git a/lib/ruby_units/unit.rb b/lib/ruby_units/unit.rb index e9b5dbd..77a8c53 100644 --- a/lib/ruby_units/unit.rb +++ b/lib/ruby_units/unit.rb @@ -61,10 +61,10 @@ class << self DIGITS_REGEX = /\d+/.freeze # 0, 1, 2, 3 DECIMAL_REGEX = /\d*[.]?#{DIGITS_REGEX}/.freeze # 1, 0.1, .1 # Rational number, including improper fractions: 1 2/3, -1 2/3, 5/3, etc. - RATIONAL_NUMBER = %r{\(?(?:(?#{SIGN_REGEX}#{DECIMAL_REGEX})[ -])?(?#{SIGN_REGEX}#{DECIMAL_REGEX})/(?#{SIGN_REGEX}#{DECIMAL_REGEX})\)?}.freeze # 1 2/3, -1 2/3, 5/3, 1-2/3, (1/2) etc. + RATIONAL_NUMBER = %r{\(?(?:(?#{SIGN_REGEX}#{DECIMAL_REGEX})[ -])?(?#{SIGN_REGEX}#{DECIMAL_REGEX})/(?#{SIGN_REGEX}#{DECIMAL_REGEX})\)?} # 1 2/3, -1 2/3, 5/3, 1-2/3, (1/2) etc. # Scientific notation: 1, -1, +1, 1.2, +1.2, -1.2, 123.4E5, +123.4e5, # -123.4E+5, -123.4e-5, etc. - SCI_NUMBER = /([+-]?\d*[.]?\d+(?:[Ee][+-]?\d+(?![.]))?)/.freeze + SCI_NUMBER = /([+-]?\d*[.]?\d+(?:[Ee][+-]?\d+(?![.]))?)/ # ideally we would like to generate this regex from the alias for a 'feet' # and 'inches', but they aren't defined at the point in the code where we # need this regex. @@ -83,11 +83,6 @@ class << self STONE_LB_REGEX = /(?#{INTEGER_REGEX})\s*#{STONE_LB_UNIT_REGEX}/.freeze # Time formats: 12:34:56,78, (hh:mm:ss,msec) etc. TIME_REGEX = /(?\d+):(?\d+):?(?:(?\d+))?(?:[.](?\d+))?/.freeze - # Scientific notation: 1, -1, +1, 1.2, +1.2, -1.2, 123.4E5, +123.4e5, - # -123.4E+5, -123.4e-5, etc. - SCI_NUMBER = /([+-]?\d*[.]?\d+(?:[Ee][+-]?)?\d*)/.freeze - # Rational number, including improper fractions: 1 2/3, -1 2/3, 5/3, etc. - RATIONAL_NUMBER = %r{\(?([+-])?(\d+[ -])?(\d+)/(\d+)\)?}.freeze # Complex numbers: 1+2i, 1.0+2.0i, -1-1i, etc. COMPLEX_NUMBER = /(?#{SCI_NUMBER})?(?#{SCI_NUMBER})i\b/.freeze # Any Complex, Rational, or scientific number diff --git a/spec/ruby_units/unit_spec.rb b/spec/ruby_units/unit_spec.rb index aa9a9af..80b821b 100644 --- a/spec/ruby_units/unit_spec.rb +++ b/spec/ruby_units/unit_spec.rb @@ -597,14 +597,14 @@ end end - describe RubyUnits::Unit.new("1:23:45,67") do + describe RubyUnits::Unit.new("1:23:45.67") do it { is_expected.to be_an_instance_of Unit } describe '#scalar' do subject { super().scalar } it { is_expected.to be_a(Numeric) } - it { is_expected.to be === 5025000067/3600000000r } + it { is_expected.to be === 5025067/3600000r } end describe '#units' do