@@ -4,7 +4,13 @@ defmodule Transport.Validators.NeTEx.MetadataExtractor do
44 - start_date and end_date (from calendar and service calendars)
55 """
66
7+ alias Transport.NeTEx.ArchiveParser
8+
79 def extract ( filepath ) do
10+ Map . merge ( extract_validity_dates ( filepath ) , extract_networks ( filepath ) )
11+ end
12+
13+ def extract_validity_dates ( filepath ) do
814 case validity_dates ( filepath ) do
915 { start_date , end_date } ->
1016 % {
@@ -19,6 +25,12 @@ defmodule Transport.Validators.NeTEx.MetadataExtractor do
1925 _ -> no_validity_dates ( )
2026 end
2127
28+ def extract_networks ( filepath ) do
29+ % { "networks" => run_parser ( filepath , & ArchiveParser . read_all_networks / 1 ) }
30+ rescue
31+ _ -> % { "networks" => [ ] }
32+ end
33+
2234 defp no_validity_dates , do: % { "no_validity_dates" => true }
2335
2436 defp validity_dates ( filepath ) do
@@ -30,14 +42,16 @@ defmodule Transport.Validators.NeTEx.MetadataExtractor do
3042 end
3143
3244 defp validity_dates_from_calendars ( filepath ) do
33- filepath
34- |> Transport.NeTEx.ArchiveParser . read_all_calendars ( )
35- |> flatten ( )
45+ run_parser ( filepath , & ArchiveParser . read_all_calendars / 1 )
3646 end
3747
3848 defp validity_dates_from_service_calendars ( filepath ) do
49+ run_parser ( filepath , & ArchiveParser . read_all_service_calendars / 1 )
50+ end
51+
52+ defp run_parser ( filepath , parser ) do
3953 filepath
40- |> Transport.NeTEx.ArchiveParser . read_all_service_calendars ( )
54+ |> parser . ( )
4155 |> flatten ( )
4256 end
4357
0 commit comments