map-tube 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +170 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/data/barcelona-map.xml +82 -0
- data/data/berlin-map.xml +343 -0
- data/data/bucharest-map.xml +76 -0
- data/data/budapest-map.xml +71 -0
- data/data/delhi-map.xml +156 -0
- data/data/glasgow-map.xml +23 -0
- data/data/kazan-map.xml +20 -0
- data/data/kiev-map.xml +103 -0
- data/data/koln-map.xml +398 -0
- data/data/kuala_lampur-map.xml +167 -0
- data/data/london-map.xml +378 -0
- data/data/lyon-map.xml +54 -0
- data/data/malaga-map.xml +30 -0
- data/data/minsk-map.xml +41 -0
- data/data/moscow-map.xml +239 -0
- data/data/new_york-map.xml +105 -0
- data/data/prague-map.xml +76 -0
- data/data/saint_petersburg-map.xml +90 -0
- data/data/singapore-map.xml +133 -0
- data/data/sofia-map.xml +39 -0
- data/data/tblisi-map.xml +36 -0
- data/data/tokyo-map.xml +146 -0
- data/data/vienna-map.xml +127 -0
- data/data/warsow-map.xml +40 -0
- data/lib/map/tube/exceptions.rb +10 -0
- data/lib/map/tube/graph.rb +102 -0
- data/lib/map/tube/line.rb +13 -0
- data/lib/map/tube/map_loader.rb +34 -0
- data/lib/map/tube/parser.rb +54 -0
- data/lib/map/tube/route.rb +19 -0
- data/lib/map/tube/station.rb +20 -0
- data/lib/map/tube/version.rb +5 -0
- data/lib/map/tube.rb +21 -0
- data/map-tube.gemspec +28 -0
- metadata +158 -0
data/data/vienna-map.xml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahn_Wien -->
|
3
|
+
<tube name="U-Bahn Wien">
|
4
|
+
<lines>
|
5
|
+
<line id="U1" name="U-Bahn-Linie U1" color="red"/>
|
6
|
+
<line id="U2" name="U-Bahn-Linie U2" color="magenta"/>
|
7
|
+
<line id="U3" name="U-Bahn-Linie U3" color="orange"/>
|
8
|
+
<line id="U4" name="U-Bahn-Linie U4" color="green"/>
|
9
|
+
<line id="U6" name="U-Bahn-Linie U6" color="brown"/>
|
10
|
+
</lines>
|
11
|
+
<stations>
|
12
|
+
|
13
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahnlinie_1_(Wien) -->
|
14
|
+
<station id="1-01" name="Reumannplatz" line="U1:1" link="1-02"/>
|
15
|
+
<station id="1-02" name="Keplerplatz" line="U1:2" link="1-01,1-03"/>
|
16
|
+
<station id="1-03" name="Südtiroler Platz-Hauptbahnhof" line="U1:3" link="1-02,1-04"/>
|
17
|
+
<station id="1-04" name="Taubstummengasse" line="U1:4" link="1-03,1-05"/>
|
18
|
+
<station id="1-05" name="Karlsplatz" line="U1:5" link="1-04,1-06" other_link="Tunnel:2-20,Tunnel:4-12"/>
|
19
|
+
<station id="1-06" name="Stephansplatz" line="U1:6" link="1-05,1-07" other_link="Tunnel:3-11"/>
|
20
|
+
<station id="1-07" name="Schwedenplatz" line="U1:7" link="1-06,1-08" other_link="Tunnel:4-15"/>
|
21
|
+
<station id="1-08" name="Nestroyplatz" line="U1:8" link="1-07,1-09"/>
|
22
|
+
<station id="1-09" name="Praterstern" line="U1:9" link="1-08,1-10" other_link="Tunnel:2-13"/>
|
23
|
+
<station id="1-10" name="Vorgartenstraße" line="U1:10" link="1-09,1-11"/>
|
24
|
+
<station id="1-11" name="Donauinsel" line="U1:11" link="1-10,1-12"/>
|
25
|
+
<station id="1-12" name="Kaisermühlen" line="U1:12" link="1-11,1-13"/>
|
26
|
+
<station id="1-13" name="Alte Donau" line="U1:13" link="1-12,1-14"/>
|
27
|
+
<station id="1-14" name="Kagran" line="U1:14" link="1-13,1-15"/>
|
28
|
+
<station id="1-15" name="Kagraner Platz" line="U1:15" link="1-14,1-16"/>
|
29
|
+
<station id="1-16" name="Rennbahnweg" line="U1:16" link="1-15,1-17"/>
|
30
|
+
<station id="1-17" name="Aderklaaer Straße" line="U1:17" link="1-16,1-18"/>
|
31
|
+
<station id="1-18" name="Großfeldsiedlung" line="U1:18" link="1-17,1-19"/>
|
32
|
+
<station id="1-19" name="Leopoldau" line="U1:19" link="1-18"/>
|
33
|
+
|
34
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahnlinie_2_(Wien) -->
|
35
|
+
<station id="2-01" name="Seestadt" line="U2:1" link="2-02"/>
|
36
|
+
<station id="2-02" name="Aspern Nord" line="U2:2" link="2-01,2-03"/>
|
37
|
+
<station id="2-03" name="Hausfeldstraße" line="U2:3" link="2-02,2-04"/>
|
38
|
+
<station id="2-04" name="Aspernstraße" line="U2:4" link="2-03,2-05"/>
|
39
|
+
<station id="2-05" name="Donauspital" line="U2:5" link="2-04,2-06"/>
|
40
|
+
<station id="2-06" name="Hardeggasse" line="U2:6" link="2-05,2-07"/>
|
41
|
+
<station id="2-07" name="Stadlau" line="U2:7" link="2-06,2-08"/>
|
42
|
+
<station id="2-08" name="Donaustadtbrücke" line="U2:8" link="2-07,2-09"/>
|
43
|
+
<station id="2-09" name="Donaumarina" line="U2:9" link="2-08,2-10"/>
|
44
|
+
<station id="2-10" name="Stadion" line="U2:10" link="2-09,2-11"/>
|
45
|
+
<station id="2-11" name="Krieau" line="U2:11" link="2-10,2-12"/>
|
46
|
+
<station id="2-12" name="Messe-Prater" line="U2:12" link="2-11,2-13"/>
|
47
|
+
<station id="2-13" name="Praterstern" line="U2:13" link="2-12,2-14" other_link="Tunnel:1-09"/>
|
48
|
+
<station id="2-14" name="Taborstraße" line="U2:14" link="2-13,2-15"/>
|
49
|
+
<station id="2-15" name="Schottenring" line="U2:15" link="2-14,2-16" other_link="Tunnel:4-16"/>
|
50
|
+
<station id="2-16" name="Schottentor" line="U2:16" link="2-15,2-17"/>
|
51
|
+
<station id="2-17" name="Rathaus" line="U2:17" link="2-16,2-18"/>
|
52
|
+
<station id="2-18" name="Volkstheater" line="U2:18" link="2-17,2-19" other_link="Tunnel:3-09"/>
|
53
|
+
<station id="2-19" name="Museumsquartier" line="U2:19" link="2-18,2-20"/>
|
54
|
+
<station id="2-20" name="Karlsplatz" line="U2:20" link="2-19" other_link="Tunnel:1-05,Tunnel:4-12"/>
|
55
|
+
|
56
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahnlinie_3_(Wien) -->
|
57
|
+
<station id="3-01" name="Ottakring" line="U3:1" link="3-02"/>
|
58
|
+
<station id="3-02" name="Kendlerstraße" line="U3:2" link="3-01,3-03"/>
|
59
|
+
<station id="3-03" name="Hütteldorfer Straße" line="U3:3" link="3-02,3-04"/>
|
60
|
+
<station id="3-04" name="Johnstraße" line="U3:4" link="3-03,3-05"/>
|
61
|
+
<station id="3-05" name="Schweglerstraße" line="U3:5" link="3-04,3-06"/>
|
62
|
+
<station id="3-06" name="Westbahnhof" line="U3:6" link="3-05,3-07" other_link="Tunnel:6-11"/>
|
63
|
+
<station id="3-07" name="Zieglergasse" line="U3:7" link="3-06,3-08"/>
|
64
|
+
<station id="3-08" name="Neubaugasse" line="U3:8" link="3-07,3-09"/>
|
65
|
+
<station id="3-09" name="Volkstheater" line="U3:9" link="3-08,3-10" other_link="Tunnel:2-18"/>
|
66
|
+
<station id="3-10" name="Herrengasse" line="U3:10" link="3-09,3-11"/>
|
67
|
+
<station id="3-11" name="Stephansplatz" line="U3:11" link="3-10,3-12" other_link="Tunnel:1-06"/>
|
68
|
+
<station id="3-12" name="Stubentor" line="U3:12" link="3-11,3-13"/>
|
69
|
+
<station id="3-13" name="Landstraße" line="U3:13" link="3-12,3-14" other_link="Tunnel:4-14"/>
|
70
|
+
<station id="3-14" name="Rochusgasse" line="U3:14" link="3-13,3-15"/>
|
71
|
+
<station id="3-15" name="Kardinal-Nagl-Platz" line="U3:15" link="3-14,3-16"/>
|
72
|
+
<station id="3-16" name="Schlachthausgasse" line="U3:16" link="3-15,3-17"/>
|
73
|
+
<station id="3-17" name="Erdberg" line="U3:17" link="3-16,3-18"/>
|
74
|
+
<station id="3-18" name="Gasometer" line="U3:18" link="3-17,3-19"/>
|
75
|
+
<station id="3-19" name="Zippererstraße" line="U3:19" link="3-18,3-20"/>
|
76
|
+
<station id="3-20" name="Enkplatz" line="U3:20" link="3-19,3-21"/>
|
77
|
+
<station id="3-21" name="Simmering" line="U3:21" link="3-20"/>
|
78
|
+
|
79
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahnlinie_4_(Wien) -->
|
80
|
+
<station id="4-01" name="Hütteldorf" line="U4:1" link="4-02"/>
|
81
|
+
<station id="4-02" name="Ober St. Veit" line="U4:2" link="4-01,4-03"/>
|
82
|
+
<station id="4-03" name="Unter St. Veit" line="U4:3" link="4-02,4-04"/>
|
83
|
+
<station id="4-04" name="Braunschweiggasse" line="U4:4" link="4-03,4-05"/>
|
84
|
+
<station id="4-05" name="Hietzing" line="U4:5" link="4-04,4-06"/>
|
85
|
+
<station id="4-06" name="Schönbrunn" line="U4:6" link="4-05,4-07"/>
|
86
|
+
<station id="4-07" name="Meidling Hauptstraße" line="U4:7" link="4-06,4-08"/>
|
87
|
+
<station id="4-08" name="Längenfeldgasse" line="U4:8" link="4-07,4-09" other_link="Tunnel:6-09"/>
|
88
|
+
<station id="4-09" name="Margaretengürtel" line="U4:9" link="4-08,4-10"/>
|
89
|
+
<station id="4-10" name="Pilgramgasse" line="U4:10" link="4-09,4-11"/>
|
90
|
+
<station id="4-11" name="Kettenbrückengasse" line="U4:11" link="4-10,4-12"/>
|
91
|
+
<station id="4-12" name="Karlsplatz" line="U4:12" link="4-11,4-13" other_link="Tunnel:1-05,Tunnel:2-20"/>
|
92
|
+
<station id="4-13" name="Stadtpark" line="U4:13" link="4-12,4-14"/>
|
93
|
+
<station id="4-14" name="Landstraße" line="U4:14" link="4-13,4-15" other_link="Tunnel:3-13"/>
|
94
|
+
<station id="4-15" name="Schwedenplatz" line="U4:15" link="4-14,4-16" other_link="Tunnel:1-07"/>
|
95
|
+
<station id="4-16" name="Schottenring" line="U4:16" link="4-15,4-17" other_link="Tunnel:2-15"/>
|
96
|
+
<station id="4-17" name="Roßauer Lände" line="U4:17" link="4-16,4-18"/>
|
97
|
+
<station id="4-18" name="Friedensbrücke" line="U4:18" link="4-17,4-19"/>
|
98
|
+
<station id="4-19" name="Spittelau" line="U4:19" link="4-18,4-20" other_link="Tunnel:6-19"/>
|
99
|
+
<station id="4-20" name="Heiligenstadt" line="U4:20" link="4-19"/>
|
100
|
+
|
101
|
+
<!-- https://de.wikipedia.org/wiki/U-Bahnlinie_6_(Wien) -->
|
102
|
+
<station id="6-01" name="Siebenhirten" line="U6:1" link="6-02"/>
|
103
|
+
<station id="6-02" name="Perfektastraße" line="U6:2" link="6-01,6-03"/>
|
104
|
+
<station id="6-03" name="Erlaaer Straße" line="U6:3" link="6-02,6-04"/>
|
105
|
+
<station id="6-04" name="Alterlaa" line="U6:4" link="6-03,6-05"/>
|
106
|
+
<station id="6-05" name="Am Schöpfwerk" line="U6:5" link="6-04,6-06"/>
|
107
|
+
<station id="6-06" name="Tscherttegasse" line="U6:6" link="6-05,6-07"/>
|
108
|
+
<station id="6-07" name="Bahnhof Meidling" line="U6:7" link="6-06,6-08"/>
|
109
|
+
<station id="6-08" name="Niederhofstraße" line="U6:8" link="6-07,6-09"/>
|
110
|
+
<station id="6-09" name="Längenfeldgasse" line="U6:9" link="6-08,6-10" other_link="Tunnel:4-08"/>
|
111
|
+
<station id="6-10" name="Gumpendorfer Straße" line="U6:10" link="6-09,6-11"/>
|
112
|
+
<station id="6-11" name="Westbahnhof" line="U6:11" link="6-10,6-12" other_link="Tunnel:3-06"/>
|
113
|
+
<station id="6-12" name="Burggasse-Stadthalle" line="U6:12" link="6-11,6-13"/>
|
114
|
+
<station id="6-13" name="Thaliastraße" line="U6:13" link="6-12,6-14"/>
|
115
|
+
<station id="6-14" name="Josefstädter Straße" line="U6:14" link="6-13,6-15"/>
|
116
|
+
<station id="6-15" name="Alser Straße" line="U6:15" link="6-14,6-16"/>
|
117
|
+
<station id="6-16" name="Michelbeuern-AKH" line="U6:16" link="6-15,6-17"/>
|
118
|
+
<station id="6-17" name="Währinger Straße-Volksoper" line="U6:17" link="6-16,6-18"/>
|
119
|
+
<station id="6-18" name="Nußdorfer Straße" line="U6:18" link="6-17,6-19"/>
|
120
|
+
<station id="6-19" name="Spittelau" line="U6:19" link="6-18,6-20" other_link="Tunnel:4-19"/>
|
121
|
+
<station id="6-20" name="Jägerstraße" line="U6:20" link="6-19,6-21"/>
|
122
|
+
<station id="6-21" name="Dresdner Straße" line="U6:21" link="6-20,6-22"/>
|
123
|
+
<station id="6-22" name="Handelskai" line="U6:22" link="6-21,6-23"/>
|
124
|
+
<station id="6-23" name="Neue Donau" line="U6:23" link="6-22,6-24"/>
|
125
|
+
<station id="6-24" name="Floridsdorf" line="U6:24" link="6-23"/>
|
126
|
+
</stations>
|
127
|
+
</tube>
|
data/data/warsow-map.xml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!-- https://pl.wikipedia.org/wiki/Metro_w_Warszawie -->
|
3
|
+
<tube name="Metro w Warszawie">
|
4
|
+
<lines>
|
5
|
+
<line id="M1" name="Linia M1" color="blue"/>
|
6
|
+
<line id="M2" name="Linia M2" color="red"/>
|
7
|
+
</lines>
|
8
|
+
<stations>
|
9
|
+
<!-- https://pl.wikipedia.org/wiki/Linia_M1_metra_w_Warszawie -->
|
10
|
+
<station id="A1" name="Kabaty" line="Linia M1" link="A2"/>
|
11
|
+
<station id="A2" name="Natolin" line="Linia M1" link="A1,A3"/>
|
12
|
+
<station id="A3" name="Imielin" line="Linia M1" link="A2,A4"/>
|
13
|
+
<station id="A4" name="Stokłosy" line="Linia M1" link="A3,A5"/>
|
14
|
+
<station id="A5" name="Ursynów" line="Linia M1" link="A4,A6"/>
|
15
|
+
<station id="A6" name="Służew" line="Linia M1" link="A5,A7"/>
|
16
|
+
<station id="A7" name="Wilanowska" line="Linia M1" link="A6,A8"/>
|
17
|
+
<station id="A8" name="Wierzbno" line="Linia M1" link="A7,A9"/>
|
18
|
+
<station id="A9" name="Racławicka" line="Linia M1" link="A8,A10"/>
|
19
|
+
<station id="A10" name="Pole Mokotowskie" line="Linia M1" link="A9,A11"/>
|
20
|
+
<station id="A11" name="Politechnika" line="Linia M1" link="A10,A13"/>
|
21
|
+
<station id="A13" name="Centrum" line="Linia M1" link="A11,A14"/>
|
22
|
+
<station id="A14" name="Świętokrzyska" line="Linia M1" link="A13,A15" other_link="Tunnel:C11"/>
|
23
|
+
<station id="A15" name="Ratusz Arsenał" line="Linia M1" link="A14,A17"/>
|
24
|
+
<station id="A17" name="Dworzec Gdański" line="Linia M1" link="A15,A18"/>
|
25
|
+
<station id="A18" name="Plac Wilsona" line="Linia M1" link="A17,A19"/>
|
26
|
+
<station id="A19" name="Marymont" line="Linia M1" link="A18,A20"/>
|
27
|
+
<station id="A20" name="Słodowiec" line="Linia M1" link="A19,A21"/>
|
28
|
+
<station id="A21" name="Stare Bielany" line="Linia M1" link="A20,A22"/>
|
29
|
+
<station id="A22" name="Wawrzyszew" line="Linia M1" link="A21,A23"/>
|
30
|
+
<station id="A23" name="Młociny" line="Linia M1" link="A22"/>
|
31
|
+
|
32
|
+
<station id="C9" name="Rondo Daszyńskiego" line="Linia M2" link="C10"/>
|
33
|
+
<station id="C10" name="Rondo ONZ" line="Linia M2" link="C9,C11"/>
|
34
|
+
<station id="C11" name="Świętokrzyska" line="Linia M2" link="C10,C12" other_link="Tunnel:A14"/>
|
35
|
+
<station id="C12" name="Nowy Świat-Uniwersytet" line="Linia M2" link="C11,C13"/>
|
36
|
+
<station id="C13" name="Centrum Nauki Kopernik" line="Linia M2" link="C12,C14"/>
|
37
|
+
<station id="C14" name="Stadion Narodowy" line="Linia M2" link="C13,C15"/>
|
38
|
+
<station id="C15" name="Dworzec Wileński" line="Linia M2" link="C14"/>
|
39
|
+
</stations>
|
40
|
+
</tube>
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Map
|
2
|
+
module Tube
|
3
|
+
class Graph
|
4
|
+
attr_accessor :stations, :lines
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@stations = []
|
8
|
+
@lines = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_station(station)
|
12
|
+
@stations << station
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_line(line)
|
16
|
+
@lines << line
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_shortest_route(from_station_name, to_station_name)
|
20
|
+
from_station = get_station_by_name(from_station_name)
|
21
|
+
to_station = get_station_by_name(to_station_name)
|
22
|
+
compute_shortest_path(from_station, to_station)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_station_by_id(station_id)
|
26
|
+
find_by(:station, :id, station_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_station_by_name(station_name)
|
30
|
+
find_by(:station, :name, station_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_line_by_id(line_id)
|
34
|
+
find_by(:line, :id, line_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_line_by_name(line_name)
|
38
|
+
find_by(:line, :name, line_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def find_by(model, attribute, value)
|
44
|
+
get_instance_for_model(model).each do |obj|
|
45
|
+
return obj if obj.send(attribute) == value
|
46
|
+
end
|
47
|
+
|
48
|
+
raise_error_for_model(model, attribute, value)
|
49
|
+
end
|
50
|
+
|
51
|
+
def compute_shortest_path(from_station, to_station)
|
52
|
+
raise_error_for_model(:route) if from_station.id == to_station.id
|
53
|
+
|
54
|
+
route = Route.new(from_station, to_station)
|
55
|
+
visited, queue = [], []
|
56
|
+
edge = {}
|
57
|
+
|
58
|
+
queue << from_station
|
59
|
+
visited << from_station
|
60
|
+
|
61
|
+
while queue.any?
|
62
|
+
curr_station = queue.shift
|
63
|
+
break if curr_station.id == to_station.id
|
64
|
+
|
65
|
+
curr_station.links.each do |link|
|
66
|
+
next_station = get_station_by_id(link)
|
67
|
+
next if visited.include?(next_station)
|
68
|
+
queue << next_station
|
69
|
+
visited << next_station
|
70
|
+
edge[link] = curr_station
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
loop do
|
75
|
+
to_station = edge[to_station.id]
|
76
|
+
break if to_station.id == from_station.id
|
77
|
+
route.intermediate_stations.unshift(to_station)
|
78
|
+
end
|
79
|
+
|
80
|
+
route
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_instance_for_model(model)
|
84
|
+
{
|
85
|
+
:station => @stations,
|
86
|
+
:line => @lines
|
87
|
+
}[model]
|
88
|
+
end
|
89
|
+
|
90
|
+
def raise_error_for_model(model, attribute=nil, value=nil)
|
91
|
+
case model
|
92
|
+
when :station
|
93
|
+
raise(Map::Tube::Exceptions::StationException, "Station with #{attribute}='#{value}' does not exist")
|
94
|
+
when :line
|
95
|
+
raise(Map::Tube::Exceptions::LineException, "Line with #{attribute}='#{value}' does not exist")
|
96
|
+
when :route
|
97
|
+
raise(Map::Tube::Exceptions::RouteException, "Stations must be different")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Map
|
2
|
+
module Tube
|
3
|
+
class MapLoader
|
4
|
+
attr_accessor :city, :map_path
|
5
|
+
|
6
|
+
def initialize(city_name, map_path=nil)
|
7
|
+
@city = city_name.split(' ').join("_")
|
8
|
+
if map_path # Always trust the path if it comes from the user
|
9
|
+
@map_path = map_path
|
10
|
+
else
|
11
|
+
@map_path = set_path_for_city
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def read
|
16
|
+
if File.exist?(@map_path)
|
17
|
+
Parser.new(File.open(@map_path)).parse!
|
18
|
+
else
|
19
|
+
raise Map::Tube::Exceptions::CityException, "Map for #{@city} does not exist"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_path_for_city
|
26
|
+
"data/#{filename(@city)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def filename(city_name)
|
30
|
+
"#{city_name.downcase}-map.xml"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Map
|
2
|
+
module Tube
|
3
|
+
class Parser
|
4
|
+
def initialize(doc)
|
5
|
+
@document = Nokogiri::XML(doc)
|
6
|
+
@graph = Graph.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse!
|
10
|
+
parse_lines!
|
11
|
+
parse_stations!
|
12
|
+
@graph
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_stations!
|
18
|
+
stations = @document.search("//stations/station")
|
19
|
+
stations.each do |station|
|
20
|
+
current_station = Station.new(
|
21
|
+
station["id"],
|
22
|
+
station["name"],
|
23
|
+
parse_line(station["line"]))
|
24
|
+
|
25
|
+
links = station["link"].split(",")
|
26
|
+
links += compute_other_links(station["other_link"]) if station["other_link"]
|
27
|
+
links.each { |link| current_station.add_link(link) }
|
28
|
+
|
29
|
+
@graph.add_station(current_station)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_lines!
|
34
|
+
lines = @document.search("//lines/line")
|
35
|
+
lines.each do |line|
|
36
|
+
element = Line.new(line["id"], line["name"], line["color"])
|
37
|
+
@graph.add_line(element)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_line(line)
|
42
|
+
if line.include?(":")
|
43
|
+
line[/(.*):/, 1]
|
44
|
+
else
|
45
|
+
line
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def compute_other_links(links)
|
50
|
+
links.split(",").map! { |e| e.split(":")[1] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Map
|
2
|
+
module Tube
|
3
|
+
class Route
|
4
|
+
attr_accessor :departure_station, :arrival_station, :intermediate_stations
|
5
|
+
|
6
|
+
def initialize(departure_station, arrival_station)
|
7
|
+
@departure_station = departure_station
|
8
|
+
@arrival_station = arrival_station
|
9
|
+
@intermediate_stations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def pretty
|
13
|
+
[self.departure_station.name,
|
14
|
+
self.intermediate_stations.map(&:name),
|
15
|
+
self.arrival_station.name].flatten.join(" -> ")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
module Map
|
4
|
+
module Tube
|
5
|
+
class Station
|
6
|
+
attr_accessor :id, :name, :line, :links
|
7
|
+
|
8
|
+
def initialize(id, name, line)
|
9
|
+
@id = id
|
10
|
+
@name = name
|
11
|
+
@line = line
|
12
|
+
@links = Set.new()
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_link(link)
|
16
|
+
@links << link
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/map/tube.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "map/tube/version"
|
3
|
+
require "map/tube/exceptions"
|
4
|
+
require "map/tube/station"
|
5
|
+
require "map/tube/line"
|
6
|
+
require "map/tube/route"
|
7
|
+
require "map/tube/graph"
|
8
|
+
require "map/tube/parser"
|
9
|
+
require "map/tube/map_loader"
|
10
|
+
|
11
|
+
module Map
|
12
|
+
module Tube
|
13
|
+
def self.new(city_name)
|
14
|
+
MapLoader.new(city_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.new_from_xml(city_name, xml_file_path)
|
18
|
+
MapLoader.new(city_name, xml_file_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/map-tube.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'map/tube/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "map-tube"
|
8
|
+
spec.version = Map::Tube::VERSION
|
9
|
+
spec.authors = ["Radu-Bogdan Croitoru"]
|
10
|
+
spec.email = ["croitoruradubogdan@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Core library to process the map data}
|
13
|
+
spec.description = %q{The core module to process the map data. It provides the the interface to find the shortest route in terms of stoppage between two nodes.}
|
14
|
+
spec.homepage = "https://github.com/radubogdan/map-tube"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.10.3'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: map-tube
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Radu-Bogdan Croitoru
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.3
|
83
|
+
description: The core module to process the map data. It provides the the interface
|
84
|
+
to find the shortest route in terms of stoppage between two nodes.
|
85
|
+
email:
|
86
|
+
- croitoruradubogdan@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- data/barcelona-map.xml
|
101
|
+
- data/berlin-map.xml
|
102
|
+
- data/bucharest-map.xml
|
103
|
+
- data/budapest-map.xml
|
104
|
+
- data/delhi-map.xml
|
105
|
+
- data/glasgow-map.xml
|
106
|
+
- data/kazan-map.xml
|
107
|
+
- data/kiev-map.xml
|
108
|
+
- data/koln-map.xml
|
109
|
+
- data/kuala_lampur-map.xml
|
110
|
+
- data/london-map.xml
|
111
|
+
- data/lyon-map.xml
|
112
|
+
- data/malaga-map.xml
|
113
|
+
- data/minsk-map.xml
|
114
|
+
- data/moscow-map.xml
|
115
|
+
- data/new_york-map.xml
|
116
|
+
- data/prague-map.xml
|
117
|
+
- data/saint_petersburg-map.xml
|
118
|
+
- data/singapore-map.xml
|
119
|
+
- data/sofia-map.xml
|
120
|
+
- data/tblisi-map.xml
|
121
|
+
- data/tokyo-map.xml
|
122
|
+
- data/vienna-map.xml
|
123
|
+
- data/warsow-map.xml
|
124
|
+
- lib/map/tube.rb
|
125
|
+
- lib/map/tube/exceptions.rb
|
126
|
+
- lib/map/tube/graph.rb
|
127
|
+
- lib/map/tube/line.rb
|
128
|
+
- lib/map/tube/map_loader.rb
|
129
|
+
- lib/map/tube/parser.rb
|
130
|
+
- lib/map/tube/route.rb
|
131
|
+
- lib/map/tube/station.rb
|
132
|
+
- lib/map/tube/version.rb
|
133
|
+
- map-tube.gemspec
|
134
|
+
homepage: https://github.com/radubogdan/map-tube
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.5.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Core library to process the map data
|
158
|
+
test_files: []
|