Current section

Files

Jump to
tesourex lib helper.ex
Raw

lib/helper.ex

defmodule Tesourex.Helper do
def most_recent(a, b) do
case Date.compare(to_date(a[:last_updated_at]), to_date(b[:last_updated_at])) do
:gt -> a
_ -> b
end
end
def to_date(tesouro_date) do
parts = tesouro_date
|> String.split("/")
|> Enum.reverse
|> Enum.map(&String.to_integer/1)
{:ok, date} = apply(&Date.new/3, parts)
date
end
def parse_value(string) do
{integer, _} = string
|> String.replace(~r/[R\$\.\,]/, "")
|> Integer.parse
integer / 100
end
end