defmodule CoreData do defstruct name: nil, version: nil, entities: [] def parse(contents) do contents |> Floki.parse |> parse_model end def attr(name, attrs) do :proplists.get_value(name, attrs) end def to_bool(str) when str == "YES", do: true def to_bool(_), do: false defp parse_model({"model", attributes, contents}) do %CoreData{ name: attr("name", attributes), version: attr("systemversion", attributes), entities: CoreData.Entity.parse(contents, []) } end end