From 572776deef6734bd656daaf35ad4eb46b07f038f Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Thu, 23 Jun 2011 14:28:15 -0700 Subject: [PATCH] remove the need for space between number and units --- lib/ruby_units/unit.rb | 2 +- spec/ruby-units/unit_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/ruby_units/unit.rb b/lib/ruby_units/unit.rb index 461e33fa..6b70dd3c 100644 --- a/lib/ruby_units/unit.rb +++ b/lib/ruby_units/unit.rb @@ -1250,7 +1250,7 @@ def self.parse_into_numbers_and_units(string) rational = %r{[+-]?\d+\/\d+} # complex numbers... -1.2+3i, +1.2-3.3i complex = %r{#{sci}{2,2}i} - anynumber = %r{(?:(#{complex}|#{rational}|#{sci})\b)?\s?([\D].*)?} + anynumber = %r{(#{complex}|#{rational}|#{sci})?\s?([\D].*)?} num, unit = string.scan(anynumber).first [case num when NilClass diff --git a/spec/ruby-units/unit_spec.rb b/spec/ruby-units/unit_spec.rb index bb68d83a..ca987252 100644 --- a/spec/ruby-units/unit_spec.rb +++ b/spec/ruby-units/unit_spec.rb @@ -107,6 +107,36 @@ its(:base) {should == Unit("0.001 m")} end + describe Unit("1g") do + it {should be_a Numeric} + it {should be_an_instance_of Unit} + its(:scalar) {should == 1} + its(:scalar) {should be_an Integer} + its(:units) {should == "g"} + its(:kind) {should == :mass} + it {should_not be_temperature} + it {should_not be_degree} + it {should_not be_base} + it {should_not be_unitless} + it {should_not be_zero} + its(:base) {should == subject} + end + + describe Unit("1.4g") do + it {should be_a Numeric} + it {should be_an_instance_of Unit} + its(:scalar) {should === 1.4} + its(:scalar) {should be_a Float} + its(:units) {should == "g"} + its(:kind) {should == :mass} + it {should_not be_temperature} + it {should_not be_degree} + it {should_not be_base} + it {should_not be_unitless} + it {should_not be_zero} + its(:base) {should == subject} + end + describe Unit("10 m/s^2") do it {should be_an_instance_of Unit} its(:scalar) {should == 10}