map-tube 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54c19572c9c5bd8108363649f92204d97205aad5
4
- data.tar.gz: 6275af06c1c3930f9e652a33d33c443285ca234c
3
+ metadata.gz: 969c908fbae9ad892bd9a950d04cb36c4210437b
4
+ data.tar.gz: 19d7d41fbb2cf78603ffc9d4e2008ac077f54d89
5
5
  SHA512:
6
- metadata.gz: e692f5fbc03013fc8cb4e17389237d46589fc806b2338d110321c81fe3df4b2244d8b6714f748616ec665a5815f71ba648c46a5546b0eee7940bb26caf7cc978
7
- data.tar.gz: dc9b023db52dcb0d46eab9db473a9e5001b148b7fdb530d5569792e3e4abc678a771ccd76eaafc4562003456b170a284c5ca2136ecc8a440212e371b42ee8bab
6
+ metadata.gz: 3f93048cb3dc393c01a62a1940b137c1caa4bf7180d86654726e723f6ea5682034f76731f8dae5e56bd8ec3d326a067e71b3f6d335706a04821b6d6039c7ab5c
7
+ data.tar.gz: a94c4e1ba0cdc66bf6df745df3b5cf22497247f19c3475f87fb3181a35af4106842d9ebb95e219298661ff5b019e1cd24349a690f49a92da4c60b5069eedd1e9
data/.travis.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.4
3
+ - 2.2.3
4
4
  before_install: gem install bundler -v 1.11.2
5
+
6
+ script: 'bundle exec rspec spec/'
7
+
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - croitoruradubogdan@gmail.com
12
+ on_failure: change
13
+ on_success: never
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Map::Tube
2
2
 
3
+ [![Build Status](https://travis-ci.org/radubogdan/map-tube.svg?branch=master)](https://travis-ci.org/radubogdan/map-tube)
4
+ [![Gem Version](https://badge.fury.io/rb/map-tube.svg)](https://badge.fury.io/rb/map-tube)
5
+
3
6
  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
7
 
5
8
  ## Installation
@@ -85,6 +88,15 @@ route.pretty
85
88
  # => "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
89
  ```
87
90
 
91
+ **Generate images**
92
+
93
+ ```ruby
94
+ bucharest = Map::Tube.new("Bucharest").read;
95
+ bucharest.graphviz.generate.output(png: "bucharest.png")
96
+ ```
97
+
98
+ ![Bucharest](http://i.imgur.com/8RBuGi6.png)
99
+
88
100
  ## Documentation
89
101
 
90
102
  **Map::Tube**
@@ -117,6 +129,8 @@ route.pretty
117
129
  - line - Map::Tube::Line object
118
130
  - `#add_station(station)` *-> Map::Tube::Graph*
119
131
  - station - Map::Tube::Station object
132
+ - `#to_h` *-> Hash*
133
+ - `#graphviz` *->Map::Tube::Graphviz*
120
134
 
121
135
  **Map::Tube::Line**
122
136
  - `.new(id, name, color)`
@@ -154,6 +168,11 @@ route.pretty
154
168
  - path - String - path to xml
155
169
  - `#parse` *-> Map::Tube::Graph*
156
170
 
171
+ **Map::Tube::Graphviz**
172
+ - `.new(graph)`
173
+ - graph - Map::Tube::Graph
174
+ - `#generate` *-> GraphViz*
175
+
157
176
  **Map::Tube::Exceptions**
158
177
  - StationException
159
178
  - LineException
@@ -168,3 +187,7 @@ Bug reports and pull requests are welcome on GitHub at [radubogdan/map-tube](htt
168
187
  ## License
169
188
 
170
189
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
190
+
191
+ ## Thanks
192
+
193
+ - [Manwar](https://github.com/Manwar/Map-Tube) for the idea.
@@ -38,6 +38,22 @@ module Map
38
38
  find_by(:line, :name, line_name)
39
39
  end
40
40
 
41
+ def to_h
42
+ {}.tap do |hash|
43
+ @stations.each do |station|
44
+ hash[station.name] = []
45
+ station.links.each do |link|
46
+ curr_link = self.get_station_by_id(link)
47
+ hash[station.name] << curr_link.name unless curr_link.name == station.name
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def graphviz
54
+ Graphviz.new(self)
55
+ end
56
+
41
57
  private
42
58
 
43
59
  def find_by(model, attribute, value)
@@ -0,0 +1,18 @@
1
+ module Map
2
+ module Tube
3
+ class Graphviz
4
+ attr_accessor :graph, :g
5
+
6
+ def initialize(graph)
7
+ @graph = graph
8
+ @g = GraphViz.new(:G, type: :digraph, concentrate: true)
9
+ end
10
+
11
+ def generate
12
+ @g.add(@graph.to_h)
13
+ @g
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Map
2
2
  module Tube
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/map/tube.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "nokogiri"
2
+ require "graphviz"
2
3
  require "map/tube/version"
3
4
  require "map/tube/exceptions"
4
5
  require "map/tube/station"
@@ -7,6 +8,7 @@ require "map/tube/route"
7
8
  require "map/tube/graph"
8
9
  require "map/tube/parser"
9
10
  require "map/tube/map_loader"
11
+ require "map/tube/graphviz"
10
12
 
11
13
  module Map
12
14
  module Tube
data/map-tube.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_runtime_dependency 'nokogiri', '~> 1.6'
23
+ spec.add_runtime_dependency 'ruby-graphviz', '~> 1.2'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.11"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: map-tube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radu-Bogdan Croitoru
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-10 00:00:00.000000000 Z
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-graphviz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +138,7 @@ files:
124
138
  - lib/map/tube.rb
125
139
  - lib/map/tube/exceptions.rb
126
140
  - lib/map/tube/graph.rb
141
+ - lib/map/tube/graphviz.rb
127
142
  - lib/map/tube/line.rb
128
143
  - lib/map/tube/map_loader.rb
129
144
  - lib/map/tube/parser.rb