Skip to content

Commit

Permalink
remove the need for space between number and units
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jun 23, 2011
1 parent e7ef676 commit 572776d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby_units/unit.rb
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/ruby-units/unit_spec.rb
Expand Up @@ -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}
Expand Down

0 comments on commit 572776d

Please sign in to comment.