Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Adds ability for concentrations to convert to a scalar denom uom #50

Merged
merged 1 commit into from
Feb 9, 2016
Merged
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
7 changes: 6 additions & 1 deletion lib/unit/concentration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def convert_to(uom)
if uoms.size <= 1
raise IncompatibleUnitsError
end
Concentration.new(numerator.convert_to(uoms[0]), denominator.convert_to(uoms[1]))
tokens = Lexer.new.tokenize("1 #{uom}")
destination_conc = Parser.new.parse(tokens)
Concentration.new(
numerator.convert_to(destination_conc.numerator.uom).scale(destination_conc.scalar),
denominator.convert_to(destination_conc.denominator.uom)
)
end
alias_method :>>, :convert_to

Expand Down
6 changes: 6 additions & 0 deletions test/concentration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ class ConcentrationTest < Minitest::Test
assert_equal 2000, new_con.scalar
assert_equal 'mcg/ml', new_con.uom
end

should "convert to unit with scalar in denomatinor" do
new_con = @con >> 'mg/2ml'
assert_equal 1, new_con.scalar
assert_equal 'mg/ml', new_con.uom
end
end

context "abs" do
Expand Down