-
Notifications
You must be signed in to change notification settings - Fork 64
/
utils.ex
40 lines (36 loc) · 913 Bytes
/
utils.ex
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
defmodule Utils do
@moduledoc """
Useful utitlities for testing and processing Quotes.
"""
@doc """
cleans up quotes sourced from various places.
see: https://github.com/nelsonic/quotes/issues/1
"""
def clean do
count() # count before running
list = File.read!("quotes.json")
|> Jason.decode!
|> Enum.uniq
|> Enum.map(fn q -> # quote must not be from unknown authors
if q["author"] != "" && q["author"] != nil && q["author"] != "unknown" do
q
end
end)
|> Enum.filter(& !is_nil(&1))
|> Enum.sort_by(fn q ->
q["author"]
end)
|> Jason.encode!(pretty: true)
File.write!("quotes.json", list)
end
@doc """
count does exactly what you expect,
returns the count of quotes in quotes.json
"""
def count do
File.read!("quotes.json")
|> Jason.decode!()
|> Enum.count
|> IO.inspect(label: "count")
end
end