Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Love.Women.Creator do
- alias __MODULE__, as: WomenLoveCreator
- defstruct phrase: nil,
- women: nil,
- hapiness_level: nil,
- consequences: nil,
- women_happy?: false,
- valid?: true,
- error: nil
- def call(phrase: phrase, women: women, author: author) do
- %WomenLoveCreator{phrase: phrase, women: women, author: author}
- |> check_women_availability()
- |> check_length()
- |> check_theme()
- |> invoke_women_hapiness()
- |> transmit_consequences_to_men()
- end
- defp check_women_availability(%{women: women} = creator_struct) do
- case Women.has_face_to_sit?(women) do
- true ->
- %WomenLoveCreator{creator_struct | valid?: false, error: "There is a man under it", women_happy?: true}
- false -> creator_struct
- end
- end
- defp check_length(%{valid?: false} = creator_struct), do: creator_struct
- defp check_length(%{phrase: phrase} = creator_struct) do
- case length(phrase) == 4 do
- true -> creator_struct
- false -> %WomenLoveCreator{creator_struct | valid?: false, error: "Wrong length of phrase"}
- end
- end
- defp check_theme(%{valid?: false} = creator_struct), do: creator_struct
- defp check_theme(%{phrase: phrase} = creator_struct) do
- case SpeachAnalyzer.call(phrase: phrase, theme: :facesitting) do
- {:ok, expected_hapiness_level} ->
- %WomenLoveCreator{creator_struct | hapiness_level: expected_hapiness_level}
- {:error, _} ->
- %WomenLoveCreator{creator_struct | valid?: false, error: "Wrong theme of phrase"}
- end
- end
- defp invoke_women_hapiness(%{valid?: false} = creator_struct), do: creator_struct
- defp invoke_women_hapiness(%{hapiness_level: hapiness_level} = creator_struct) do
- case Women.invoke_hapiness(hapiness_level) do
- {:ok, consequences} -> %WomenLoveCreator{creator_struct | consequences: consequences, women_happy?: true}
- {:error, consequences} -> %WomenLoveCreator{creator_struct | consequences: consequences, women_happy?: false}
- end
- end
- defp transmit_consequences_to_men(%{valid?: false} = creator_struct), do: creator_struct
- defp transmit_consequences_to_men(%{women_happy?: women_happy?, consequences: consequences, author: author, women: women}) do
- case women_happy? do
- true -> Man.use_consequences(man: author, consequences: consequences, women: women)
- false -> Man.run_from_responsibility(man: author, consequences: consequences, women: women)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement