Created
October 19, 2016 14:44
-
-
Save Hajto/783e2a921b8cbe91cefb816c81204001 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Kpsz.Ecto.Point do | |
@behaviour Ecto.Type | |
@moduledoc """ | |
Representation of geological point in the database | |
""" | |
@extractor ~r/\(([\d.]+),([\d.]+)\)/ | |
def type, do: :string | |
def cast(string) when is_binary(string), do: {:ok, string} | |
def cast(_), do: :error | |
def load(string) do | |
case Regex.run(@extractor, string) do | |
[_whole, x, y] -> {:ok, {x, y} } | |
_ -> :error | |
end | |
end | |
def loard(_), do: :error | |
def dump({ x, y}), do: {:ok, "(#{x},#{y})" } | |
def dump(_), do: :error | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment