exercism/elixir/bob/lib/bob.ex

24 lines
558 B
Elixir

defmodule Bob do
@spec hey(String.t()) :: String.t()
def hey(input) do
trimmed = String.trim(input)
is_yell? = String.upcase(trimmed) == trimmed and String.downcase(trimmed) != trimmed
is_question? = String.ends_with?(trimmed, "?")
is_silence? = trimmed == ""
cond do
is_silence? ->
"Fine. Be that way!"
is_yell? and is_question? ->
"Calm down, I know what I'm doing!"
is_question? ->
"Sure."
is_yell? ->
"Whoa, chill out!"
true ->
"Whatever."
end
end
end