Packages

Parse and generate XML using DSL extension of Ecto.Schema.

Current section

Files

Jump to
xml_schema lib type cents.ex
Raw

lib/type/cents.ex

defmodule XmlSchema.Type.Cents do
@moduledoc """
Converts float currency with cents into integer cents.
"""
use Ecto.Type
def type, do: :integer
def cast(string) when is_binary(string),
do: (String.to_float(string) * 100) |> trunc
def cast(string) when is_list(string),
do: cast(to_string(string))
def dump(cents), do: cents
def equal?(a, b), do: a == b
def load(cents), do: cents
end