-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcond.exs
More file actions
27 lines (23 loc) · 681 Bytes
/
cond.exs
File metadata and controls
27 lines (23 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
defmodule Account do
def transfer_amount(from_account, to_account, amount) do
hourOfDay = DateTime.utc_now.hour
if !valid_transfer?(amount, hourOfDay) do
{ _ , message } = { :error, "Invalid Transfer" }
message
else
perform_transfer(from_account, to_account, amount)
end
end
def valid_transfer?(amount, hourOfDay) do
cond do
hourOfDay < 12 -> amount <= 5000
hourOfDay < 18 -> amount <= 1000
true -> amount <= 300
end
end
def perform_transfer(from_account, to_account, amount) do
"FROM:#{from_account} TO:#{to_account} AMOUNT: #{amount}"
end
end
Account.transfer_amount(112233, 445566, 980)
|> IO.puts