map-tube 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54c19572c9c5bd8108363649f92204d97205aad5
4
+ data.tar.gz: 6275af06c1c3930f9e652a33d33c443285ca234c
5
+ SHA512:
6
+ metadata.gz: e692f5fbc03013fc8cb4e17389237d46589fc806b2338d110321c81fe3df4b2244d8b6714f748616ec665a5815f71ba648c46a5546b0eee7940bb26caf7cc978
7
+ data.tar.gz: dc9b023db52dcb0d46eab9db473a9e5001b148b7fdb530d5569792e3e4abc678a771ccd76eaafc4562003456b170a284c5ca2136ecc8a440212e371b42ee8bab
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in map-tube.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Radu-Bogdan Croitoru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # Map::Tube
2
+
3
+ The core module to process the map data. It provides the interface to find the shortest route in terms of stoppage between two nodes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'map-tube'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install map-tube
20
+
21
+ ## Usage
22
+
23
+ **Load maps and read them**
24
+
25
+ ```ruby
26
+ require 'map/tube'
27
+
28
+ # Load from available cities
29
+ bucharest = Map::Tube.new("Bucharest").read
30
+ london = Map::Tube.new("London").read
31
+
32
+ # Or load your xml
33
+ mycity = Map::Tube.new_from_xml("My City", "path/to/xml").read
34
+ ```
35
+
36
+ **Line/Station names**
37
+
38
+ ```ruby
39
+ bucharest.lines.map(&:name) # => ["Linia M1", "Linia M2", "Linia M3", "Linia M4"]
40
+ bucharest.stations.map(&:name)
41
+ ```
42
+
43
+ **Get the shortest path between two stations**
44
+
45
+ ```ruby
46
+ route = london.get_shortest_route("Paddington", "Monument")
47
+ => #<Map::Tube::Route:0x007fd81986b160
48
+ @arrival_station=#<Map::Tube::Station:0x007fd819168430 @id="M009", @line="Circle,District", @links=#<Set: {"T009", "C008", "B003"}>, @name="Monument">,
49
+ @departure_station=#<Map::Tube::Station:0x007fd818b953a0 @id="P001", @line="District,Circle,Hammersmith & City,Bakerloo", @links=#<Set: {"B008", "W007", "E011", "R010"}>, @name="Paddington">,
50
+ @intermediate_stations=
51
+ [#<Map::Tube::Station:0x007fd8191ba230 @id="E011", @line="Circle,District,Hammersmith & City,Bakerloo", @links=#<Set: {"P001", "M005", "B001"}>, @name="Edgware Road">,
52
+ #<Map::Tube::Station:0x007fd818c3c8f8
53
+ @id="B001",
54
+ @line="Circle,Hammersmith & City,Bakerloo,Metropolitan,Jubilee",
55
+ @links=#<Set: {"B018", "R004", "M005", "G008", "S023", "E011", "F004"}>,
56
+ @name="Baker Street">,
57
+ #<Map::Tube::Station:0x007fd818c1eb50 @id="B018", @line="Central,Jubilee", @links=#<Set: {"G009", "B001", "O005", "M004"}>, @name="Bond Street">,
58
+ #<Map::Tube::Station:0x007fd818bdf3d8 @id="G009", @line="Victoria,Jubilee,Piccadilly", @links=#<Set: {"V002", "O005", "B018", "W027", "H036", "P006"}>, @name="Green Park">,
59
+ #<Map::Tube::Station:0x007fd818af7bf0 @id="W027", @line="Circle,District,Jubilee", @links=#<Set: {"S022", "G009", "W008", "E015"}>, @name="Westminster">,
60
+ #<Map::Tube::Station:0x007fd8191486f8 @id="W008", @line="Northern,Bakerloo,Jubilee,Waterloo & City", @links=#<Set: {"E015", "L002", "W027", "S021", "B003", "K001"}>, @name="Waterloo">,
61
+ #<Map::Tube::Station:0x007fd818c37b28 @id="B003", @line="Central,DLR,Northern,Waterloo & City", @links=#<Set: {"S002", "S024", "L013", "M011", "L012", "W008", "M009"}>, @name="Bank">]>
62
+
63
+ route.pretty
64
+ # => "Paddington -> Edgware Road -> Baker Street -> Bond Street -> Green Park -> Westminster -> Waterloo -> Bank -> Monument"
65
+ ```
66
+
67
+ ```ruby
68
+ route = bucharest.get_shortest_route("Dristor 1", "Pipera")
69
+
70
+ # => #<Map::Tube::Route:0x007f9769c5a550
71
+ @arrival_station=#<Map::Tube::Station:0x007f976a08e310 @id="M2-01", @line="M2", @links=#<Set: {"M2-02"}>, @name="Pipera">,
72
+ @departure_station=#<Map::Tube::Station:0x007f976a08fa30 @id="M1-17", @line="M1", @links=#<Set: {"M1-16", "M1-18", "M3-11"}>, @name="Dristor 1">,
73
+ @intermediate_stations=
74
+ [#<Map::Tube::Station:0x007f976a08ff58 @id="M1-16", @line="M1", @links=#<Set: {"M1-15", "M1-17", "M3-10"}>, @name="Mihai Bravu">,
75
+ #<Map::Tube::Station:0x007f97698261f0 @id="M1-15", @line="M1", @links=#<Set: {"M1-14", "M1-16", "M3-09"}>, @name="Timpuri Noi">,
76
+ #<Map::Tube::Station:0x007f976982c208 @id="M1-14", @line="M1", @links=#<Set: {"M1-13", "M1-15", "M3-08", "M2-07"}>, @name="Piața Unirii 1">,
77
+ #<Map::Tube::Station:0x007f976a08cdd0 @id="M2-07", @line="M2", @links=#<Set: {"M2-06", "M2-08", "M3-08"}>, @name="Piața Unirii 2">,
78
+ #<Map::Tube::Station:0x007f976a08d118 @id="M2-06", @line="M2", @links=#<Set: {"M2-05", "M2-07"}>, @name="Universitate">,
79
+ #<Map::Tube::Station:0x007f976a08d460 @id="M2-05", @line="M2", @links=#<Set: {"M2-04", "M2-06"}>, @name="Piața Romană">,
80
+ #<Map::Tube::Station:0x007f976a08d988 @id="M2-04", @line="M2", @links=#<Set: {"M2-03", "M2-05", "M1-06"}>, @name="Piața Victoriei">,
81
+ #<Map::Tube::Station:0x007f976a08dcd0 @id="M2-03", @line="M2", @links=#<Set: {"M2-02", "M2-04"}>, @name="Aviatorilor">,
82
+ #<Map::Tube::Station:0x007f976a08e018 @id="M2-02", @line="M2", @links=#<Set: {"M2-01", "M2-03"}>, @name="Aurel Vlaicu">]>
83
+
84
+ route.pretty
85
+ # => "Dristor 1 -> Mihai Bravu -> Timpuri Noi -> Piața Unirii 1 -> Piața Unirii 2 -> Universitate -> Piața Romană -> Piața Victoriei -> Aviatorilor -> Aurel Vlaicu -> Pipera"
86
+ ```
87
+
88
+ ## Documentation
89
+
90
+ **Map::Tube**
91
+ - `.new(city_name)` *-> Map::Tube::Loader*
92
+ - `.new_from_xml(city_name, path_to_xml)` *-> Map::Tube::Loader*
93
+
94
+ **Map::Tube::Loader**
95
+ - `.new(city_name, map_path=nil)`
96
+ - *(mandatory)* city_name - String - It should match a city in data/ dir
97
+ - *(optional)* map_path - String - Path to local xml
98
+ - `#city`
99
+ - `#map_path`
100
+ - `#read` *-> Map::Tube::Graph*
101
+
102
+ **Map::Tube::Graph**
103
+ - `#stations` *-> Array [ Map::Tube::Station ]*
104
+ - `#lines` *-> Array [ Map::Tube::Line ]*
105
+ - `#get_shortest_route(from_station_name, to_station_name)` *-> Map::Tube::Route*
106
+ - from_station_name - String - Name of departure station
107
+ - to_station_name - String - Name of arrival station
108
+ - `#get_station_by_id(station_id)` *-> Map::Tube::Station*
109
+ - station_id - String - Unique identifier of the station
110
+ - `#get_station_by_name(station_name)` *-> Map::Tube::Station*
111
+ - station_name - String - Name of the station
112
+ - `#get_line_by_id(line_id)` *-> Map::Tube::Line*
113
+ - line_id - String - Unique identifier of the line
114
+ - `#get_line_by_name(line_name)` *-> Map::Tube::Line*
115
+ - line_name - String - Name of the line
116
+ - `#add_line(line)` *-> Map::Tube::Graph*
117
+ - line - Map::Tube::Line object
118
+ - `#add_station(station)` *-> Map::Tube::Graph*
119
+ - station - Map::Tube::Station object
120
+
121
+ **Map::Tube::Line**
122
+ - `.new(id, name, color)`
123
+ - id - String - unique identifier of the Line
124
+ - name - String - name of the line
125
+ - color - String - color of the line
126
+ - `#id`
127
+ - `#name`
128
+ - `#color`
129
+
130
+ **Map::Tube::Station**
131
+ - `.new(id, name, line)`
132
+ - id - String - unique identifier of the Station
133
+ - name - String - name of the Station
134
+ - line - String - line that supports the Station
135
+ - `#id`
136
+ - `#name`
137
+ - `#line`
138
+ - `#links` *-> Set { String }*
139
+ - `#add_link(link)`
140
+ - link - String - unique identifier of the station
141
+
142
+ **Map::Tube::Route**
143
+ - `.new(departure_station, arrival_station)`
144
+ - departure_station - Map::Tube::Station
145
+ - arrival_station - Map::Tube::Station
146
+ - `#departure_station` *-> Map::Tube::Station*
147
+ - `#arrival_station` *-> Map::Tube::Station*
148
+ - `#intermediate_stations` *-> Array [ Map::Tube::Station ]*
149
+ - `#pretty` *-> String*
150
+
151
+ **Map::Tube::Parser**
152
+ - `.new(file_handle)`
153
+ - file_handle - File.open(path)
154
+ - path - String - path to xml
155
+ - `#parse` *-> Map::Tube::Graph*
156
+
157
+ **Map::Tube::Exceptions**
158
+ - StationException
159
+ - LineException
160
+ - RouteException
161
+ - CityException
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at [radubogdan/map-tube](https://github.com/radubogdan/map-tube).
166
+
167
+
168
+ ## License
169
+
170
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "map/tube"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,82 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <tube name="Barcelona Metro">
3
+ <lines>
4
+ <line id="L1" name="L1" color="#8B0000" /><!-- Red -->
5
+ <line id="L2" name="L2" color="#551A8B" /><!-- Purple -->
6
+ <line id="L3" name="L3" color="#006400" /><!-- Green -->
7
+ <line id="L4" name="L4" color="#FFFF00" /><!-- Yellow -->
8
+ <line id="L5" name="L5" color="#000080" /><!-- Blue -->
9
+ <line id="L6" name="L6" color="#551A8B" /><!-- Purple -->
10
+ <line id="L7" name="L7" color="#550000" /><!-- Brown -->
11
+ <line id="L8" name="L8" color="#FF4F00" /><!-- Orange -->
12
+ <line id="L9" name="L9" color="#FF4F00" /><!-- Orange -->
13
+ <line id="L10" name="L10" color="#000080" /><!-- Blue -->
14
+ <line id="L11" name="L11" color="#006400" /><!-- Green -->
15
+ </lines>
16
+
17
+ <stations>
18
+ <station id="TRINITAT-NOVA" name="Trinitat Nova" line="L3,L4,L11" link="L04-02,L11-04,L03-25"/>
19
+ <station id="VALL-D'HEBRON" name="Vall d'Hebron" line="L3,L5" link="L03-21,L03-19"/>
20
+ <station id="DIAGONAL" name="Diagonal" line="L5,L6,L3" link="L03-16,PASSEIG-DE-GRACIA"/>
21
+ <station id="PASSEIG-DE-GRACIA" name="Passeig de Gràcia" line="L2,L3,L4" link="L04-09,URQUINAONA,DIAGONAL,CATALUNYA"/>
22
+ <station id="CATALUNYA" name="Catalunya" line="L1,L3,L7" link="PASSEIG-DE-GRACIA,L03-12"/>
23
+ <station id="PARAL-LEL" name="Paral-lel" line="L2,L3" link="L03-09,L03-11"/>
24
+ <station id="ESPANYA" name="Espanya" line="L1,L3,L8" link="L03-07,L03-09,L08-10"/>
25
+ <station id="SANTS-ESTACIA" name="Sants Estació" line="L3,L5" link="L03-05,L03-07"/>
26
+ <station id="VERDAGUER" name="Verdaguer" line="L4,L5" link="L04-07,L04-09,DIAGONAL"/>
27
+ <station id="URQUINAONA" name="Urquinaona" line="L1,L4" link="PASSEIG-DE-GRACIA,L04-12"/>
28
+
29
+ <station id="L03-01" name="Zona Universitària" line="L3" link="L03-02"/>
30
+ <station id="L03-02" name="Palau Reial" line="L3" link="L03-03,L03-01"/>
31
+ <station id="L03-03" name="Maria Cristina" line="L3" link="L03-04,L03-02"/>
32
+ <station id="L03-04" name="Les Corts" line="L3" link="L03-05,L03-03"/>
33
+ <station id="L03-05" name="Plaça del Centre" line="L3" link="SANTS-ESTACIA,L03-04"/>
34
+ <station id="L03-07" name="Tarragona" line="L3" link="ESPANYA,SANTS-ESTACIA"/>
35
+ <station id="L03-09" name="Poble Sec" line="L3" link="PARAL-LEL,ESPANYA"/>
36
+ <station id="L03-11" name="Drassenes" line="L3" link="L03-12,PARAL-LEL"/>
37
+ <station id="L03-12" name="Liceu" line="L3" link="CATALUNYA,L03-11"/>
38
+ <station id="L03-16" name="Fontana" line="L3" link="DIAGONAL,L03-17"/>
39
+ <station id="L03-17" name="Lesseps" line="L3" link="L03-16,L03-18"/>
40
+ <station id="L03-18" name="Vallcarca" line="L3" link="L03-17,L03-19"/>
41
+ <station id="L03-19" name="Penitents" line="L3" link="L03-18,VALL-D'HEBRON"/>
42
+ <station id="L03-21" name="Montbau" line="L3" link="VALL-D'HEBRON,L03-22"/>
43
+ <station id="L03-22" name="Mundet" line="L3" link="L03-21,VALL-D'HEBRON"/>
44
+ <station id="L03-23" name="Validaura" line="L3" link="L03-22,L03-24"/>
45
+ <station id="L03-24" name="Canyelles" line="L3" link="L03-23,L03-25"/>
46
+ <station id="L03-25" name="Roquetes" line="L3" link="L03-24,TRINITAT-NOVA"/>
47
+
48
+ <station id="L04-02" name="Via Júlia" line="L4" link="TRINITAT-NOVA,L04-03"/>
49
+ <station id="L04-03" name="Llucmajor" line="L4" link="L04-02,L04-04"/>
50
+ <station id="L04-04" name="Maragall" line="L4" link="L04-03,L04-05"/>
51
+ <station id="L04-05" name="Guinardó" line="L4" link="L04-04,L04-06"/>
52
+ <station id="L04-06" name="Alfons X" line="L4" link="L04-05,L04-07"/>
53
+ <station id="L04-07" name="Joanic" line="L4" link="L04-06,VERDAGUER"/>
54
+ <station id="L04-09" name="Girona" line="L4" link="VERDAGUER,PASSEIG-DE-GRACIA"/>
55
+ <station id="L04-12" name="Jaume I" line="L4" link="URQUINAONA,L04-13"/>
56
+ <station id="L04-13" name="Barceloneta" line="L4" link="L04-12,L04-14"/>
57
+ <station id="L04-14" name="Ciutadella-Vila Olimpica" line="L4" link="L04-13,L04-15"/>
58
+ <station id="L04-15" name="Bogatell" line="L4" link="L04-14,L04-16"/>
59
+ <station id="L04-16" name="Llacuna" line="L4" link="L04-15,L04-17"/>
60
+ <station id="L04-17" name="Poble Nou" line="L4" link="L04-16,L04-18"/>
61
+ <station id="L04-18" name="Selva de Mar" line="L4" link="L04-17,L04-19"/>
62
+ <station id="L04-19" name="El Maresme-Fòrum" line="L4" link="L04-18,L04-20"/>
63
+ <station id="L04-20" name="Besòs Mar" line="L4" link="L04-19,L04-21"/>
64
+ <station id="L04-21" name="La Pau" line="L4" link="L04-20"/>
65
+
66
+ <station id="L08-01" name="Moli Nou-ciutat Cooperativa" line="L8" link="L08-02"/>
67
+ <station id="L08-02" name="Sant Boi" line="L8" link="L08-01,L08-03"/>
68
+ <station id="L08-03" name="Cornella-Riera" line="L8" link="L08-02,L08-04"/>
69
+ <station id="L08-04" name="Almeda" line="L8" link="L08-03,L08-05"/>
70
+ <station id="L08-05" name="Av Carrilet" line="L8" link="L08-04,L08-06"/>
71
+ <station id="L08-06" name="St. Josep" line="L8" link="L08-05,L08-07"/>
72
+ <station id="L08-07" name="Gornal" line="L8" link="L08-06,L08-08"/>
73
+ <station id="L08-08" name="Europa Fira" line="L8" link="L08-07,L08-09"/>
74
+ <station id="L08-09" name="Ildefons Cerda" line="L8" link="L08-08,L08-10"/>
75
+ <station id="L08-10" name="Magoria La Campana" line="L8" link="L08-09,ESPANYA"/>
76
+
77
+ <station id="L11-01" name="Can Cuiàs" line="L11" link="L11-02"/>
78
+ <station id="L11-02" name="Ciutat Meridiana" line="L11" link="L11-03,L11-01"/>
79
+ <station id="L11-03" name="Torre Baró-Vallbona" line="L11" link="L11-04,L11-02"/>
80
+ <station id="L11-04" name="Casa de l'Aigua" line="L11" link="TRINITAT-NOVA,L11-03"/>
81
+ </stations>
82
+ </tube>