@@ -22,6 +22,7 @@ defmodule CLDRex.Parsers.XMLParser do
22
22
end
23
23
24
24
defp process_file ( file ) do
25
+ IO . puts "Processing #{ inspect ( file ) } "
25
26
# the replace is an ugly hack because the doc uses a relative path which
26
27
# breaks at compile time, so we need to change that path
27
28
doc = @ main_path
@@ -35,20 +36,21 @@ defmodule CLDRex.Parsers.XMLParser do
35
36
display_pattern: extract_display_pattern ( doc ) ,
36
37
languages: extract_languages ( doc ) ,
37
38
territories: extract_territories ( doc ) ,
38
- calendar: extract_calendar ( doc )
39
+ calendar: extract_calendar ( doc ) ,
40
+ numbers: Map . get ( extract_numbers ( doc ) , :numbers , % { } )
39
41
} )
40
42
end
41
43
42
44
defp extract_display_pattern ( doc ) do
43
45
doc
44
- |> xpath ( ~x" //localeDisplayPattern/localePattern/text()" )
46
+ |> xpath ( ~x" //localeDisplayPattern/localePattern/text()" s )
45
47
|> to_string
46
48
end
47
49
48
50
defp extract_languages ( doc ) do
49
51
doc
50
52
|> xpath ( ~x" //languages/language" l ,
51
- locale: ~x" ./@type" , language: ~x" ./text()" )
53
+ locale: ~x" ./@type" , language: ~x" ./text()" s )
52
54
|> Enum . reduce ( % { } , fn ( l , acc ) ->
53
55
loc = l . locale |> to_string |> String . to_atom
54
56
lng = l . language |> to_string
@@ -59,14 +61,53 @@ defmodule CLDRex.Parsers.XMLParser do
59
61
defp extract_territories ( doc ) do
60
62
doc
61
63
|> xpath ( ~x" //territories/territory" l ,
62
- un_code: ~x" ./@type" , name: ~x" ./text()" )
64
+ un_code: ~x" ./@type" , name: ~x" ./text()" s )
63
65
|> Enum . reduce ( % { } , fn ( l , acc ) ->
64
66
code = l . un_code |> to_string |> String . to_atom
65
67
name = l . name |> to_string
66
68
Map . put ( acc , code , name )
67
69
end )
68
70
end
69
71
72
+ defp extract_numbers ( doc ) do
73
+ numbers = xpath ( doc , ~x" //numbers" e )
74
+
75
+ case numbers do
76
+ nil -> % { }
77
+ _ ->
78
+ numbers_map = xmap ( doc , numbers: [
79
+ ~x" //numbers" ,
80
+ decimal_pattern: ~x" ./decimalFormats/decimalFormatLength/decimalFormat/pattern[1]/text()" s ,
81
+ decimal_formats: [
82
+ ~x" ./decimalFormats/decimalFormatLength" l ,
83
+ type: ~x" ./@type" ,
84
+ patterns: [
85
+ ~x" ./decimalFormat/pattern" l ,
86
+ type: ~x" ./@type" ,
87
+ count: ~x" ./@count" ,
88
+ pattern: ~x" ./text()" s
89
+ ]
90
+ ]
91
+ ] )
92
+
93
+ symbols = if xpath ( numbers , ~x" //numbers/symbols" e ) do
94
+ xmap ( numbers , symbols: [
95
+ ~x" //numbers/symbols" ,
96
+ decimal: ~x" ./decimal/text()" s ,
97
+ group: ~x" ./group/text()" s ,
98
+ percent: ~x" ./percentSign/text()" s ,
99
+ plus: ~x" ./plusSign/text()" s ,
100
+ minus: ~x" ./minusSign/text()" s
101
+ ] )
102
+ end
103
+
104
+ case symbols do
105
+ nil -> numbers_map
106
+ _ -> put_in ( numbers_map , [ :numbers , :symbols ] , symbols . symbols )
107
+ end
108
+ end
109
+ end
110
+
70
111
defp extract_calendar ( doc ) do
71
112
doc
72
113
|> extract_calendar_map
@@ -86,7 +127,7 @@ defmodule CLDRex.Parsers.XMLParser do
86
127
months: [
87
128
~x" ./month" l ,
88
129
month: ~x" ./@type" ,
89
- label: ~x" ./text()"
130
+ label: ~x" ./text()" s
90
131
]
91
132
]
92
133
] ,
@@ -99,24 +140,24 @@ defmodule CLDRex.Parsers.XMLParser do
99
140
days: [
100
141
~x" ./day" l ,
101
142
day: ~x" ./@type" ,
102
- label: ~x" ./text()"
143
+ label: ~x" ./text()" s
103
144
]
104
145
]
105
146
] ,
106
147
date_formats: [
107
148
~x" ./dateFormats/dateFormatLength" l ,
108
149
length: ~x" ./@type" ,
109
- format: ~x" ./dateFormat/pattern/text()"
150
+ format: ~x" ./dateFormat/pattern/text()" s
110
151
] ,
111
152
time_formats: [
112
153
~x" ./timeFormats/timeFormatLength" l ,
113
154
length: ~x" ./@type" ,
114
- format: ~x" ./timeFormat/pattern/text()"
155
+ format: ~x" ./timeFormat/pattern/text()" s
115
156
] ,
116
157
date_time_formats: [
117
158
~x" ./dateTimeFormats/dateTimeFormatLength" l ,
118
159
length: ~x" ./@type" ,
119
- format: ~x" ./dateTimeFormat/pattern/text()"
160
+ format: ~x" ./dateTimeFormat/pattern/text()" s
120
161
]
121
162
] )
122
163
end
0 commit comments