-
Notifications
You must be signed in to change notification settings - Fork 2
/
cats.exs
48 lines (38 loc) · 1006 Bytes
/
cats.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
defmodule Cats do
@prefix "/tmp"
def make do
cats |> mk
end
def cats do
[
[state: "Virginia",
cats: [[name: "Felix", age: 7],
[name: "Angel", age: 1],
[name: "Midnight", age: 9]]],
[state: "Maryland",
cats: [[name: "Pepper", age: 4],
[name: "Oreo", age: 6]]],
[state: "DC",
cats: [[name: "Tiger", age: 3],
[name: "Garfield", age: 3],
[name: "Misty", age: 8]]],
]
end
def mk_state(state) do
[@prefix, "cats", String.downcase(state)] |> Path.join |> File.mkdir_p!
end
def mk_cat(state, cat = [name: name, age: _age]) do
[@prefix, "cats", String.downcase(state), String.downcase(name) <> ".cat"]
|> Path.join
|> File.write!(Macro.to_string(cat) <> "\n")
end
def mk([]) do
# all done
end
def mk([[state: state, cats: cats] | t]) do
state |> mk_state
cats |> Enum.map(&(mk_cat(state, &1)))
mk(t)
end
end
Cats.make