adding :ets to keep track of current value
This commit is contained in:
23
lib/clip/board.ex
Normal file
23
lib/clip/board.ex
Normal 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
|
||||
Reference in New Issue
Block a user