Locale added
This commit is contained in:
32
lib/direction/direction.ex
Normal file
32
lib/direction/direction.ex
Normal file
@@ -0,0 +1,32 @@
|
||||
defmodule Localizator.Direction do
|
||||
alias Localizator.Commons
|
||||
alias Localizator.Locale
|
||||
|
||||
defstruct [:from, :to]
|
||||
|
||||
@typedoc """
|
||||
Locale
|
||||
"""
|
||||
@type locale :: String.t() | Atom.t()
|
||||
@type from :: locale
|
||||
@type from_may_be_nil :: from | nil
|
||||
@type to :: locale
|
||||
@type direction :: {from, to} | to | %{from: from, to: to} | %{to: to}
|
||||
@type direction_struct :: %{to: to, from: from_may_be_nil}
|
||||
|
||||
@spec get(direction) :: direction_struct
|
||||
def get(direction) do
|
||||
direction_map =
|
||||
case direction do
|
||||
[from: from, to: to] -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
[from, to] -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
{from, to} -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
%{from: from, to: to} -> %{to: Locale.normalize(to), from: Locale.normalize(from)}
|
||||
%{to: to} -> %{to: Locale.normalize(to), from: nil}
|
||||
[to: to] -> %{to: Locale.normalize(to), from: nil}
|
||||
to -> %{to: Locale.normalize(to), from: nil}
|
||||
end
|
||||
|
||||
Commons.struct_from_map(direction_map, as: %__MODULE__{})
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user