diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a27327..a1be3e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog + +## Version 0.1.2 + +### Bugfixes + +- Fixes bug when some names like "Никита-123" was considered valid + +### Documentation + +- Fixes formating of cases' names + + ## Version 0.1.1 ### Bugfixes @@ -13,6 +25,7 @@ - Adds `CHANGELOG.md` - Adds `CONTRIBUTING.md` + ## Version 0.1.0 - Initial release diff --git a/lib/petrovich.ex b/lib/petrovich.ex index 367c7b1..9b9181c 100644 --- a/lib/petrovich.ex +++ b/lib/petrovich.ex @@ -4,17 +4,21 @@ defmodule Petrovich do Public interface to all the functions. It can inflect first, middle, and last names. - It also can detect gender by name. ## List of cases Here's a quick reminder: > nomenative: именительный + > > genitive: родительный + > > dative: дательный + > > accusative: винительный + > > instrumental: творительный + > > prepositional: предложный """ diff --git a/lib/petrovich/detector.ex b/lib/petrovich/detector.ex index 2c5474a..f93bafe 100644 --- a/lib/petrovich/detector.ex +++ b/lib/petrovich/detector.ex @@ -42,7 +42,7 @@ defmodule Petrovich.Detector do |> String.downcase |> String.split("-") |> Enum.map(fn(item) -> prepare_value(item, exceptions, suffixes) end) - |> ResultJoiner.join_result(&join_result/1) + |> ResultJoiner.join_any_results(&join_result/1) end defp prepare_value(name, exceptions, suffixes) do diff --git a/lib/petrovich/parser.ex b/lib/petrovich/parser.ex index 8d814fc..0091f70 100644 --- a/lib/petrovich/parser.ex +++ b/lib/petrovich/parser.ex @@ -73,7 +73,7 @@ defmodule Petrovich.Parser do |> Enum.map(fn(item) -> prepare_value(item, case_, gender, exceptions, suffixes) end) - |> ResultJoiner.join_result(&join_callback/1) + |> ResultJoiner.join_all_results(&join_callback/1) end defp prepare_value(value, case_, gender, exceptions, suffixes) do diff --git a/lib/petrovich/utils/result_joiner.ex b/lib/petrovich/utils/result_joiner.ex index f4eb5cc..a667142 100644 --- a/lib/petrovich/utils/result_joiner.ex +++ b/lib/petrovich/utils/result_joiner.ex @@ -1,8 +1,16 @@ defmodule Petrovich.Utils.ResultJoiner do @moduledoc false - def join_result(results, callback) do - success = Enum.any?(results, &compare_status/1) + def join_all_results(results, callback) do + do_join(results, callback, &Enum.all?/2) + end + + def join_any_results(results, callback) do + do_join(results, callback, &Enum.any?/2) + end + + defp do_join(results, callback, check) do + success = check.(results, &compare_status/1) if success do {:ok, callback.(results)} diff --git a/mix.exs b/mix.exs index fedc6f3..0ddd110 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Petrovich.Mixfile do use Mix.Project - @version "0.1.1" + @version "0.1.2" @url "https://github.com/petrovich/petrovich_elixir" def project do diff --git a/mix.lock b/mix.lock index 314b29b..9897243 100644 --- a/mix.lock +++ b/mix.lock @@ -13,6 +13,7 @@ "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, "mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, + "ok_jose": {:hex, :ok_jose, "2.0.0", "f3ccaf78cb60785f8623efb797ff04f6272d7ff224ff2ab568c78f0ffb9cd117", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], [], "hexpm"}} diff --git a/test/petrovich_test/parser_test/edge_cases_test.exs b/test/petrovich_test/parser_test/edge_cases_test.exs new file mode 100644 index 0000000..3dec529 --- /dev/null +++ b/test/petrovich_test/parser_test/edge_cases_test.exs @@ -0,0 +1,11 @@ +defmodule PetrovichTest.ParserTest.Edge do + use ExUnit.Case + + alias Petrovich.Parser + + test "should fail on wrong names with '-'" do + assert Parser.parse( + "Никита-123", :firstname, :prepositional, :male + ) == :error + end +end