Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ruby_units/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,9 @@ def self.base_units
# @return [Array] consisting of [Numeric, "unit"]
# @private
def self.parse_into_numbers_and_units(string)
if string =~ /\$\s*(#{NUMBER_REGEX})/
string = "#{$1} USD"
end
# scientific notation.... 123.234E22, -123.456e-10
sci = %r{[+-]?\d*[.]?\d+(?:[Ee][+-]?)?\d*}
# rational numbers.... -1/3, 1/5, 20/100, -6 1/2, -6-1/2
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby-units/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@
it { subject.convert_to("in/s").should be_within(Unit("0.0001 in/s")).of(Unit("1.0043269330917 in/s")) }
end

# dollars
describe Unit("$1.45") do
it { should be_an_instance_of Unit }
it { should == Unit("1 dollar") + Unit("45 cents") }
its(:scalar) { should be_a Numeric }
its(:units) { should == "USD" }
its(:kind) { should == :currency }
it { should_not be_temperature }
it { should_not be_degree }
it { should be_base }
it { should_not be_unitless }
it { should_not be_zero }
its(:base) { should be_a Numeric }
its(:temperature_scale) { should be_nil }
end

# Farads
describe Unit("1 F") do
it { should be_an_instance_of Unit }
Expand Down