Skip to content

Commit

Permalink
Inflect - singularize word for n = 1.0 (nurugger07#88)
Browse files Browse the repository at this point in the history
* inflect singularizes for 1 and 1.0

* adds tests for inflect with 1.0
  • Loading branch information
jwebber18 authored Feb 27, 2021
1 parent a6774eb commit 1a39202
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/inflex/pluralize.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ defmodule Inflex.Pluralize do

def pluralize(word), do: find_match(@plural, word)

def inflect(word, 1), do: singularize(word)
def inflect(word, n) when n == 1, do: singularize(word)
def inflect(word, n) when is_number(n), do: pluralize(word)

defp find_match(set, word) do
Expand Down
3 changes: 3 additions & 0 deletions test/inflex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@ defmodule InflexTest do

test :inflect do
assert "child" == inflect("children", 1)
assert "child" == inflect("children", 1.0)
assert "people" == inflect("person", 2)
assert "People" == inflect("Person", 2)
assert "dogs" == inflect("dog", 3.2)
assert "slice" == inflect("slice", 1)
assert "slice" == inflect("slice", 1.0)
assert "accomplice" == inflect("accomplice", 1)
assert "accomplice" == inflect("accomplice", 1.0)
end

end

0 comments on commit 1a39202

Please sign in to comment.