Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. defmodule Love.Women.Creator do
  2. alias __MODULE__, as: WomenLoveCreator
  3.  
  4. defstruct phrase: nil,
  5. women: nil,
  6. hapiness_level: nil,
  7. consequences: nil,
  8. women_happy?: false,
  9. valid?: true,
  10. error: nil
  11.  
  12. def call(phrase: phrase, women: women, author: author) do
  13. %WomenLoveCreator{phrase: phrase, women: women, author: author}
  14. |> check_women_availability()
  15. |> check_length()
  16. |> check_theme()
  17. |> invoke_women_hapiness()
  18. |> transmit_consequences_to_men()
  19. end
  20.  
  21. defp check_women_availability(%{women: women} = creator_struct) do
  22. case Women.has_face_to_sit?(women) do
  23. true ->
  24. %WomenLoveCreator{creator_struct | valid?: false, error: "There is a man under it", women_happy?: true}
  25. false -> creator_struct
  26. end
  27. end
  28.  
  29. defp check_length(%{valid?: false} = creator_struct), do: creator_struct
  30. defp check_length(%{phrase: phrase} = creator_struct) do
  31. case length(phrase) == 4 do
  32. true -> creator_struct
  33. false -> %WomenLoveCreator{creator_struct | valid?: false, error: "Wrong length of phrase"}
  34. end
  35. end
  36.  
  37. defp check_theme(%{valid?: false} = creator_struct), do: creator_struct
  38. defp check_theme(%{phrase: phrase} = creator_struct) do
  39. case SpeachAnalyzer.call(phrase: phrase, theme: :facesitting) do
  40. {:ok, expected_hapiness_level} ->
  41. %WomenLoveCreator{creator_struct | hapiness_level: expected_hapiness_level}
  42. {:error, _} ->
  43. %WomenLoveCreator{creator_struct | valid?: false, error: "Wrong theme of phrase"}
  44. end
  45. end
  46.  
  47. defp invoke_women_hapiness(%{valid?: false} = creator_struct), do: creator_struct
  48. defp invoke_women_hapiness(%{hapiness_level: hapiness_level} = creator_struct) do
  49. case Women.invoke_hapiness(hapiness_level) do
  50. {:ok, consequences} -> %WomenLoveCreator{creator_struct | consequences: consequences, women_happy?: true}
  51. {:error, consequences} -> %WomenLoveCreator{creator_struct | consequences: consequences, women_happy?: false}
  52. end
  53. end
  54.  
  55. defp transmit_consequences_to_men(%{valid?: false} = creator_struct), do: creator_struct
  56. defp transmit_consequences_to_men(%{women_happy?: women_happy?, consequences: consequences, author: author, women: women}) do
  57. case women_happy? do
  58. true -> Man.use_consequences(man: author, consequences: consequences, women: women)
  59. false -> Man.run_from_responsibility(man: author, consequences: consequences, women: women)
  60. end
  61. end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement