-
Notifications
You must be signed in to change notification settings - Fork 71
/
basic_data_map.ex
40 lines (36 loc) · 1.37 KB
/
basic_data_map.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 Tzdata.BasicDataMap do
@moduledoc false
alias Tzdata.Parser
alias Tzdata.ParserOrganizer, as: Organizer
@file_names ~w(africa antarctica asia australasia backward etcetera europe northamerica southamerica)s
def from_files_in_dir(dir_name) do
Enum.map(@file_names, fn file_name -> {String.to_atom(file_name), Parser.read_file(file_name, dir_name)} end)
|> make_map
end
def from_single_file_in_dir(dir_name, file_name) do
[{String.to_atom(file_name), Parser.read_file(file_name, dir_name)}]
|> make_map
end
def make_map(all_files_read) do
all_files_flattened = all_files_read |> Enum.map(fn {_name, read_file} -> read_file end) |> List.flatten
rules = Organizer.rules(all_files_flattened)
zones = Organizer.zones(all_files_flattened)
links = Organizer.links(all_files_flattened)
zone_list = Organizer.zone_list(all_files_flattened)
link_list = Organizer.link_list(all_files_flattened)
zone_and_link_list = Organizer.zone_and_link_list(all_files_flattened)
by_group = all_files_read
|> Enum.map(fn {name, file_read} -> {name, Organizer.zone_and_link_list(file_read)} end)
|> Enum.into(Map.new)
{:ok,
%{rules: rules,
zones: zones,
links: links,
zone_list: zone_list,
link_list: link_list,
zone_and_link_list: zone_and_link_list,
by_group: by_group,
}
}
end
end