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

Commit

Permalink
Merge pull request #50 from kitcheck/concentration_conversion_for_sca…
Browse files Browse the repository at this point in the history
…lar_denom

Adds ability for concentrations to convert to a scalar denom uom
  • Loading branch information
Alex Johnson committed Feb 9, 2016
2 parents 9eddf56 + 5a65a86 commit 9a09abe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 9a09abe

Please sign in to comment.