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

Commit

Permalink
Merge pull request #56 from kitcheck/feature/6483_parse_each
Browse files Browse the repository at this point in the history
[Delivers #120980151] Add ability to parse 'each' and translate it to…
  • Loading branch information
Alex Johnson committed Jun 8, 2016
2 parents 320f11b + b353496 commit 33275ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/unit/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def _next_token
when (text = @ss.scan(/\b(?:unit|u)\b/i))
action { [:UNIT_UOM, text] }

when (text = @ss.scan(/\b(?:ea)\b/i))
action {[:UNITLESS_UOM, text] }
when (text = @ss.scan(/\b(?:each|ea)\b/i))
action {[:UNITLESS_UOM, 'ea'] }

when (text = @ss.scan(/\b(?:meq|eq)\b/i))
action {[:EQUIVALENCE_UOM, text] }
Expand Down
4 changes: 2 additions & 2 deletions lib/unit/lexer_definition.rex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro
MASS_UOM \b(?:mcg|mg|g)\b
VOLUME_UOM \b(?:ml|l)\b
UNIT_UOM \b(?:unit|u)\b
UNITLESS_UOM \b(?:ea)\b
UNITLESS_UOM \b(?:each|ea)\b
EQUIVALENCE_UOM \b(?:meq|eq)\b
COLON [:]
SEPERATOR [@]
Expand All @@ -29,7 +29,7 @@ rule
{UNIT_UOM} { [:UNIT_UOM, text] }

#Unitless uom
{UNITLESS_UOM} {[:UNITLESS_UOM, text] }
{UNITLESS_UOM} {[:UNITLESS_UOM, 'ea'] }

#Equivalence uom
{EQUIVALENCE_UOM} {[:EQUIVALENCE_UOM, text] }
Expand Down
2 changes: 1 addition & 1 deletion lib/unit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Unit
VERSION = "1.1.0"
VERSION = "1.2.0"
end
12 changes: 12 additions & 0 deletions test/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,17 @@ class ParserTest < Minitest::Test
assert_equal "mg/ml", conc.uom
end
end

context "unitless" do
should "parse a unitless object" do
['1 ea', '1 each'].each do |str|
unit = Unit.parse(str)

assert_equal true, unit.unit?
assert_equal 1, unit.scalar
assert_equal 'ea', unit.uom
end
end
end
end
end

0 comments on commit 33275ad

Please sign in to comment.