Skip to content

Commit

Permalink
Version 0.1.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jun 29, 2017
1 parent 041692c commit 017bcbc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +25,7 @@
- Adds `CHANGELOG.md`
- Adds `CONTRIBUTING.md`


## Version 0.1.0

- Initial release
6 changes: 5 additions & 1 deletion lib/petrovich.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: предложный
"""

Expand Down
2 changes: 1 addition & 1 deletion lib/petrovich/detector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/petrovich/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions lib/petrovich/utils/result_joiner.ex
Original file line number Diff line number Diff line change
@@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
11 changes: 11 additions & 0 deletions test/petrovich_test/parser_test/edge_cases_test.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 017bcbc

Please sign in to comment.