adding :ets to keep track of current value

This commit is contained in:
Thelonius Kort
2020-08-10 18:39:04 +02:00
parent f47f6150cb
commit a26afef638
4 changed files with 72 additions and 15 deletions

23
lib/clip/board.ex Normal file
View File

@ -0,0 +1,23 @@
defmodule Clip.Board do
alias Clip.Currents
def init(user) do
Phoenix.PubSub.subscribe(Clip.PubSub, user.email)
Currents.get(user.email)
end
def paste(user, snippet) do
Phoenix.PubSub.broadcast(Clip.PubSub, user.email, {:snippet_pasted, %{snippet: snippet}})
Currents.set(user.email, snippet)
end
def normalize(pnumber, local_pref \\ "0351", country_pref \\ "0049") do
pnumber
|> String.replace(~r/^\s*\+/, "00")
|> String.replace(~r/\D/, "")
|> String.replace(~r/^00+/, "00")
|> String.replace(~r/^(?=[1-9])/, local_pref)
|> String.replace(~r/^0(?=[1-9])/, country_pref)
end
end