rgraph 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1,5 +1,5 @@
1
1
  guard :rspec do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
2
+ watch(%r{^spec/(.+)/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)/(.+)\.rb$}) { |m| "spec/m[1]/#{m[2]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
5
  end
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/guard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby19
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'guard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('guard', 'guard')
@@ -0,0 +1,36 @@
1
+ require 'csv'
2
+ require_relative '../../lib/rgraph/link'
3
+ require_relative '../../lib/rgraph/node'
4
+
5
+
6
+ class Graph
7
+ attr_accessor :nodes, :links
8
+
9
+ def initialize(csv)
10
+ @nodes = []
11
+ @links = []
12
+ unless not csv[-4..-1] == ".csv"
13
+ CSV.foreach(csv, headers: true) do |row|
14
+ unless source = @nodes.select{|n| n.id == row['source']}.first
15
+ source = Node.new(id: row['source'])
16
+ @nodes << source
17
+ end
18
+ unless target = @nodes.select{|n| n.id == row['target']}.first
19
+ target = Node.new(id: row['target'])
20
+ @nodes << target
21
+ end
22
+ @links << Link.new(source: source, target: target, weight: row['weight'], year: row['year'])
23
+ end
24
+ else
25
+ raise Exception.new("the file must be a .csv")
26
+ end
27
+ end
28
+
29
+ def each_node(&block)
30
+ @nodes.each(&block)
31
+ end
32
+
33
+ def each_link(&block)
34
+ @links.each(&block)
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ class Link
2
+ #attr_accessor :source, :target
3
+
4
+ def initialize(arg)
5
+ @args = arg
6
+ if @args[:source] == nil
7
+ raise Exception.new("source cant be nil")
8
+ end
9
+
10
+ if @args[:target] == nil
11
+ raise Exception.new("target cant be nil")
12
+ end
13
+
14
+ if not @args[:source].is_a? Node
15
+ raise Exception.new("source must be of type Node")
16
+ end
17
+
18
+ if not @args[:target].is_a? Node
19
+ raise Exception.new("target must be of type Node")
20
+ end
21
+
22
+ @args[:weight] ||= 1
23
+
24
+ @args[:source].neighbours << @args[:target]
25
+ @args[:target].neighbours << @args[:source]
26
+ end
27
+
28
+ def method_missing(name, *args)
29
+ super unless args.empty?
30
+ @args[name]
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ class Node
2
+ attr_accessor :neighbours
3
+ def initialize(arg)
4
+ @args = arg
5
+ @neighbours = []
6
+ end
7
+
8
+ def method_missing(name, *args)
9
+ super unless args.empty?
10
+ @args[name]
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Rgraph
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/rgraph.gemspec CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 2.14.1"
24
24
  spec.add_development_dependency "guard-rspec", "~> 3.0.2"
25
-
25
+ spec.add_development_dependency "fastercsv", "~> 1.5.5"
26
26
  end
@@ -0,0 +1,447 @@
1
+ source,target,weight,year
2
+ 0034894070455412,1966638146185479,1,2005
3
+ 0034894070455412,8252965398850484,1,2005
4
+ 2352364847038041,2365330613164898,1,2005
5
+ 2352364847038041,4545190751120518,1,2005
6
+ 2352364847038041,4843726518881713,1,2005
7
+ 2352364847038041,5269607410874106,1,2005
8
+ 2352364847038041,8491363243596537,1,2005
9
+ 2352364847038041,8583077883309647,1,2005
10
+ 2365330613164898,4545190751120518,1,2005
11
+ 2365330613164898,4843726518881713,1,2005
12
+ 2365330613164898,5269607410874106,1,2005
13
+ 2365330613164898,8491363243596537,1,2005
14
+ 2365330613164898,8583077883309647,1,2005
15
+ 4545190751120518,4843726518881713,1,2005
16
+ 4545190751120518,5269607410874106,1,2005
17
+ 4545190751120518,8491363243596537,1,2005
18
+ 4545190751120518,8583077883309647,1,2005
19
+ 4843726518881713,5269607410874106,1,2005
20
+ 4843726518881713,8491363243596537,1,2005
21
+ 4843726518881713,8583077883309647,1,2005
22
+ 5269607410874106,8491363243596537,1,2005
23
+ 5269607410874106,8583077883309647,1,2005
24
+ 8491363243596537,8583077883309647,1,2005
25
+ 0079807647636803,7261961344060120,1,2005
26
+ 0079807647636803,9265320355446970,1,2005
27
+ 0079807647636803,9907101433477319,1,2005
28
+ 7261961344060120,9265320355446970,1,2005
29
+ 7261961344060120,9907101433477319,4,2005
30
+ 7261961344060120,7660947838427997,1,2005
31
+ 7261961344060120,8545749738251622,1,2005
32
+ 9265320355446970,9907101433477319,1,2005
33
+ 0210093975299031,2051626172679059,4,2005
34
+ 0210093975299031,8184042170674060,3,2005
35
+ 0210093975299031,0531184725525392,1,2005
36
+ 0210093975299031,7762631944977749,1,2005
37
+ 0210093975299031,6340987109733541,1,2005
38
+ 0531184725525392,7762631944977749,1,2005
39
+ 2559560831199977,3752466633406751,2,2005
40
+ 2559560831199977,6211659251836942,1,2005
41
+ 3752466633406751,6211659251836942,1,2005
42
+ 5760422122697584,6098050406729323,1,2005
43
+ 5760422122697584,7294579536542842,1,2005
44
+ 5760422122697584,6698384703955708,1,2005
45
+ 5760422122697584,8660713799152707,1,2005
46
+ 5760422122697584,7495136537703176,1,2005
47
+ 2678903407966360,8379515491458184,4,2005
48
+ 2678903407966360,9177121588548129,1,2005
49
+ 2678903407966360,5579868951470507,1,2005
50
+ 8379515491458184,9177121588548129,1,2005
51
+ 0305007181787906,3157693434749669,1,2005
52
+ 0305007181787906,5851604294265025,1,2005
53
+ 3157693434749669,5851604294265025,1,2005
54
+ 0310911349229745,2743748135395821,1,2005
55
+ 0310911349229745,3919711591553904,1,2005
56
+ 2743748135395821,3919711591553904,1,2005
57
+ 2330509846581060,5165158555291785,1,2005
58
+ 2749213438459449,3041207015099007,1,2005
59
+ 0383215992450256,3891648050868116,1,2005
60
+ 0383215992450256,1451068779149532,1,2005
61
+ 0395636448599186,9965276263062241,1,2005
62
+ 0398657255645016,0525343899407081,2,2005
63
+ 0431050314405943,7372780368236022,1,2005
64
+ 1352681664551083,1441035148021341,1,2005
65
+ 1352681664551083,7543542253155919,1,2005
66
+ 1441035148021341,7543542253155919,1,2005
67
+ 1441035148021341,6197248715251424,1,2005
68
+ 1441035148021341,6431550513796092,1,2005
69
+ 1441035148021341,6722041066142447,1,2005
70
+ 1441035148021341,9265320355446970,1,2005
71
+ 1441035148021341,8474196301666407,1,2005
72
+ 0586727512244467,8578050791616432,2,2005
73
+ 0950302436871091,6598548690635635,1,2005
74
+ 0950302436871091,1573488193232503,7,2005
75
+ 0950302436871091,4642643167326569,1,2005
76
+ 0950302436871091,2925730638533987,1,2005
77
+ 0950302436871091,2932247595592839,1,2005
78
+ 0950302436871091,1023970273252599,1,2005
79
+ 0950302436871091,5932757092613339,1,2005
80
+ 0950302436871091,2074336394546503,2,2005
81
+ 0674791189757357,7028403949638900,2,2005
82
+ 0675398539252938,1240227827563843,1,2005
83
+ 0675398539252938,6915714261651875,1,2005
84
+ 1240227827563843,6915714261651875,1,2005
85
+ 3150790447778819,6275124345922194,1,2005
86
+ 3150790447778819,8218059267505950,1,2005
87
+ 6275124345922194,8218059267505950,2,2005
88
+ 6275124345922194,8226529794937801,1,2005
89
+ 8218059267505950,8226529794937801,1,2005
90
+ 8218059267505950,8670247634402438,1,2005
91
+ 0743155577859174,8091857216878149,1,2005
92
+ 0817724534875188,7615891473051775,1,2005
93
+ 0842894677846904,6082640486942164,1,2005
94
+ 0867903003222790,7935238137656326,1,2005
95
+ 0916630825277350,7707689065994575,1,2005
96
+ 1418058352934773,4625288029686288,2,2005
97
+ 1418058352934773,3303963235914212,1,2005
98
+ 1573488193232503,4642643167326569,2,2005
99
+ 1573488193232503,5711934186393745,1,2005
100
+ 2925730638533987,2932247595592839,1,2005
101
+ 2925730638533987,5579868951470507,2,2005
102
+ 2925730638533987,6082640486942164,2,2005
103
+ 0988636489326998,6817674253215463,1,2005
104
+ 1002230820162670,8895005186201315,1,2005
105
+ 5579868951470507,5656733095894626,1,2005
106
+ 5579868951470507,6809125371733700,1,2005
107
+ 5579868951470507,8379515491458184,1,2005
108
+ 5579868951470507,6082640486942164,2,2005
109
+ 1053265315311978,9337709330110505,2,2005
110
+ 1254836315844697,1532329798133648,1,2005
111
+ 2615642390505378,7445566906318673,1,2005
112
+ 1289283285752334,6598548690635635,2,2005
113
+ 1316412551645220,8754335906813622,1,2005
114
+ 1316412551645220,9191945730512864,1,2005
115
+ 1316412551645220,6809125371733700,1,2005
116
+ 8754335906813622,9191945730512864,2,2005
117
+ 1398672648532107,3918921207074131,1,2005
118
+ 6197248715251424,6431550513796092,1,2005
119
+ 6197248715251424,6722041066142447,1,2005
120
+ 6197248715251424,9265320355446970,1,2005
121
+ 6197248715251424,6447163486557266,1,2005
122
+ 6197248715251424,9755286023695546,2,2005
123
+ 6197248715251424,8485576038579823,1,2005
124
+ 6431550513796092,6722041066142447,1,2005
125
+ 6431550513796092,9265320355446970,1,2005
126
+ 6722041066142447,9265320355446970,1,2005
127
+ 1548220907588612,5921185698230768,1,2005
128
+ 1548220907588612,8379515491458184,1,2005
129
+ 5921185698230768,8379515491458184,1,2005
130
+ 5921185698230768,8460306099469259,1,2005
131
+ 4642643167326569,5711934186393745,1,2005
132
+ 4642643167326569,4673198445813304,1,2005
133
+ 1582551703060830,9164877739376535,1,2005
134
+ 1681880375960859,8428074335454256,2,2005
135
+ 1681880375960859,3576569061976864,1,2005
136
+ 3576569061976864,8428074335454256,1,2005
137
+ 1693469786109191,7261961344060120,1,2005
138
+ 1697965677198993,7660947838427997,1,2005
139
+ 1955893673300502,3513735339604253,3,2005
140
+ 4809936850232418,5047132878123669,2,2005
141
+ 4809936850232418,5642915270924367,2,2005
142
+ 4809936850232418,5925881439591681,1,2005
143
+ 4809936850232418,9907101433477319,1,2005
144
+ 5047132878123669,5642915270924367,2,2005
145
+ 5047132878123669,5925881439591681,1,2005
146
+ 5047132878123669,9907101433477319,1,2005
147
+ 2003310944376439,8571576530024407,1,2005
148
+ 2003310944376439,6698384703955708,1,2005
149
+ 2148900965578428,3345663851115807,1,2005
150
+ 2148900965578428,8754335906813622,1,2005
151
+ 2148900965578428,9191945730512864,1,2005
152
+ 3345663851115807,8754335906813622,1,2005
153
+ 3345663851115807,9191945730512864,1,2005
154
+ 3345663851115807,4968158277224575,1,2005
155
+ 3345663851115807,6682146998710900,1,2005
156
+ 4311899333835868,5579868951470507,1,2005
157
+ 4311899333835868,6809125371733700,1,2005
158
+ 4312378630155156,5642915270924367,1,2005
159
+ 4312378630155156,6098050406729323,1,2005
160
+ 4312378630155156,9104198360189577,1,2005
161
+ 5642915270924367,6098050406729323,1,2005
162
+ 5642915270924367,9104198360189577,1,2005
163
+ 5642915270924367,7061953074414986,1,2005
164
+ 6098050406729323,9104198360189577,2,2005
165
+ 2302805234722051,9198865955620713,1,2005
166
+ 2302805234722051,5470389577551840,2,2005
167
+ 2302805234722051,2968694597677203,1,2005
168
+ 2313459995776080,3594843999144011,1,2005
169
+ 2315947597632104,6383021762144230,1,2005
170
+ 2315947597632104,8377972579342582,2,2005
171
+ 2315947597632104,4660433855798183,1,2005
172
+ 2458995014564228,4253908528865546,1,2005
173
+ 6690275350395550,6799982843395323,2,2005
174
+ 6139200689397504,6690275350395550,1,2005
175
+ 6139200689397504,6799982843395323,1,2005
176
+ 6139200689397504,6987563670816279,1,2005
177
+ 7660947838427997,9907101433477319,1,2005
178
+ 3333466607118191,4339782894562396,1,2005
179
+ 3333466607118191,4518052942799360,1,2005
180
+ 6669418619228798,7615891473051775,1,2005
181
+ 3337505181347965,8013405378006706,1,2005
182
+ 3337505181347965,8793599517370540,1,2005
183
+ 3337505181347965,8256254118036403,1,2005
184
+ 8013405378006706,8793599517370540,1,2005
185
+ 5549358735432795,9198272608157135,1,2005
186
+ 2932247595592839,5531054583210547,1,2005
187
+ 2932247595592839,7281338403430073,1,2005
188
+ 5531054583210547,7281338403430073,1,2005
189
+ 3919711591553904,5774807031990521,1,2005
190
+ 3919711591553904,9908417714364407,2,2005
191
+ 3919711591553904,8218059267505950,1,2005
192
+ 3294076676292528,5212837629822557,1,2005
193
+ 3294076676292528,7260065983923219,2,2005
194
+ 5212837629822557,7260065983923219,1,2005
195
+ 4327695267566592,9389378863874821,1,2005
196
+ 4327695267566592,9917047902592244,1,2005
197
+ 3129875518945632,3719659803766075,1,2005
198
+ 3129875518945632,4839958636560578,1,2005
199
+ 3129875518945632,8895005186201315,1,2005
200
+ 3719659803766075,4839958636560578,1,2005
201
+ 3719659803766075,8895005186201315,1,2005
202
+ 3719659803766075,9583145146601467,1,2005
203
+ 4839958636560578,8895005186201315,1,2005
204
+ 4839958636560578,8352922051020058,1,2005
205
+ 4839958636560578,8833561166396452,1,2005
206
+ 8341612542504580,9526156414461152,1,2005
207
+ 3201214049358628,4191789788379988,1,2005
208
+ 3201214049358628,6958241665808406,1,2005
209
+ 4968158277224575,6682146998710900,2,2005
210
+ 3452102636579964,8754335906813622,1,2005
211
+ 5315557764564865,8518098370099915,1,2005
212
+ 4022838844024162,4947186824317781,1,2005
213
+ 4022838844024162,6139200689397504,1,2005
214
+ 4022838844024162,6987563670816279,1,2005
215
+ 4947186824317781,6139200689397504,1,2005
216
+ 4947186824317781,6987563670816279,1,2005
217
+ 4190300140322728,8399257911324757,1,2005
218
+ 4408599021040004,7700733161357066,1,2005
219
+ 4408599021040004,5774807031990521,1,2005
220
+ 4454863839030427,7404029442077952,1,2005
221
+ 4454863839030427,9029835119231193,1,2005
222
+ 4454863839030427,5431600781223257,1,2005
223
+ 7404029442077952,9029835119231193,1,2005
224
+ 4704577372216652,9830587097758541,1,2005
225
+ 5925881439591681,9907101433477319,1,2005
226
+ 4950880933453890,9668040332832819,1,2005
227
+ 4950880933453890,5171165012677502,1,2005
228
+ 4950880933453890,5963049225248687,1,2005
229
+ 5116898796555782,5760422122697584,1,2005
230
+ 5384555860195426,6418768241571297,1,2005
231
+ 5384555860195426,8758191104820307,1,2005
232
+ 9223776544881741,9265604313004700,3,2005
233
+ 5498187026684158,8571576530024407,2,2005
234
+ 5498187026684158,6698384703955708,1,2005
235
+ 6698384703955708,8571576530024407,1,2005
236
+ 6698384703955708,8660713799152707,3,2005
237
+ 6698384703955708,8935733122024526,1,2005
238
+ 6958241665808406,8041290313173857,1,2005
239
+ 5695664808243549,7098642001860647,2,2005
240
+ 6817674253215463,8504093609027599,1,2005
241
+ 6473264538281674,6915714261651875,1,2005
242
+ 6473264538281674,7052822499655835,1,2005
243
+ 7663676652054207,8593011064159611,1,2005
244
+ 7955837132687218,8886634592087842,4,2005
245
+ 7955837132687218,8758395845049687,1,2005
246
+ 6707055443168938,8753457827281098,1,2005
247
+ 6800795259915680,7404029442077952,1,2005
248
+ 8571576530024407,9793295296026544,1,2005
249
+ 8571576530024407,8660713799152707,1,2005
250
+ 9029797403913218,9519251749800062,1,2005
251
+ 0006459316446998,0383215992450256,1,2005
252
+ 0043057219064007,0561003170428359,1,2005
253
+ 0045652268105107,9723365779775656,1,2005
254
+ 0066532113124336,3654988735222132,1,2005
255
+ 0066532113124336,9718076230398618,1,2005
256
+ 0068832514578140,3179079966117749,1,2005
257
+ 0123371940744034,4332588923758955,1,2005
258
+ 0123371940744034,5384555860195426,1,2005
259
+ 4332588923758955,5384555860195426,1,2005
260
+ 0191107377051312,5431600781223257,2,2005
261
+ 2051626172679059,8184042170674060,2,2005
262
+ 5277712394158254,8666548473150908,1,2005
263
+ 0284739888870695,9662960711845185,1,2005
264
+ 0299716544922235,5384555860195426,1,2005
265
+ 0320762207312409,0383215992450256,1,2005
266
+ 0320762207312409,5165808353643810,2,2005
267
+ 0320762207312409,6840818483842374,2,2005
268
+ 0320762207312409,9908596401059199,1,2005
269
+ 5165808353643810,6840818483842374,2,2005
270
+ 5165808353643810,9908596401059199,1,2005
271
+ 5165808353643810,6193845061710854,1,2005
272
+ 6840818483842374,9908596401059199,1,2005
273
+ 0350452564937100,2208634800481475,2,2005
274
+ 0358446748329067,6187420420985594,1,2005
275
+ 2932232403869135,6983477069595291,1,2005
276
+ 2932232403869135,8427741177499943,1,2005
277
+ 6983477069595291,8427741177499943,1,2005
278
+ 1221789114690533,2315947597632104,1,2005
279
+ 1221789114690533,8377972579342582,1,2005
280
+ 3041207015099007,7294579536542842,1,2005
281
+ 3041207015099007,7904583130708474,1,2005
282
+ 7294579536542842,7904583130708474,1,2005
283
+ 8758395845049687,8886634592087842,1,2005
284
+ 0561003170428359,1696412579138806,6,2005
285
+ 0561003170428359,6625577688255022,7,2005
286
+ 0561003170428359,3668865753002430,1,2005
287
+ 1696412579138806,6625577688255022,5,2005
288
+ 1696412579138806,3668865753002430,1,2005
289
+ 2333068453228104,6625577688255022,1,2005
290
+ 1654031101014216,9343857731767482,1,2005
291
+ 0533069759765601,6405948647104923,2,2005
292
+ 0633684421168567,7372780368236022,1,2005
293
+ 0633684421168567,2341026338620732,1,2005
294
+ 0633684421168567,8857252948439619,1,2005
295
+ 0637539915940739,5384555860195426,1,2005
296
+ 2872064505456567,7955837132687218,2,2005
297
+ 2872064505456567,8886634592087842,1,2005
298
+ 0672041856708192,1208755600819268,2,2005
299
+ 0759000670098689,8973828929584707,1,2005
300
+ 0769544701692080,7001550224105169,1,2005
301
+ 0999148325656924,4950880933453890,1,2005
302
+ 0999148325656924,5171165012677502,1,2005
303
+ 0999148325656924,5963049225248687,1,2005
304
+ 5171165012677502,5963049225248687,1,2005
305
+ 3540796454981012,7464404481153980,1,2005
306
+ 3540796454981012,7697752377640462,1,2005
307
+ 1007654000671281,3459819354945294,1,2005
308
+ 1023970273252599,1138433232741783,1,2005
309
+ 1088141854666563,2268635568464108,1,2005
310
+ 1088141854666563,3963435047032324,1,2005
311
+ 1088141854666563,6753120473010454,2,2005
312
+ 2268635568464108,3963435047032324,1,2005
313
+ 4329386108329268,6870721499762912,2,2005
314
+ 1148969228307246,2521824049877155,1,2005
315
+ 1172710300217932,5760422122697584,1,2005
316
+ 1172710300217932,7294579536542842,1,2005
317
+ 1210699472469839,8885496748170584,2,2005
318
+ 1291134939790347,1384125441325829,1,2005
319
+ 4654274038915572,4839958636560578,1,2005
320
+ 4654274038915572,8352922051020058,1,2005
321
+ 4654274038915572,8833561166396452,1,2005
322
+ 8352922051020058,8833561166396452,2,2005
323
+ 1342063302669283,8114535454027481,1,2005
324
+ 1384125441325829,2226590630777569,1,2005
325
+ 1484414548820375,4408599021040004,1,2005
326
+ 1567938465874195,6187420420985594,1,2005
327
+ 2924096208017273,7404029442077952,5,2005
328
+ 1589000434383051,8247182921769589,1,2005
329
+ 1593746657375208,4225912094026512,1,2005
330
+ 1596423241159372,3294076676292528,1,2005
331
+ 5547553812125672,6740018257272418,1,2005
332
+ 1685289348143002,6333263003065071,1,2005
333
+ 1777506255712474,6438645213502821,1,2005
334
+ 1795516271097895,6155994509574272,1,2005
335
+ 1819612551612136,5921185698230768,1,2005
336
+ 4170480157675812,4971259001793009,1,2005
337
+ 1869692918489026,3719659803766075,1,2005
338
+ 1869692918489026,9583145146601467,1,2005
339
+ 1966638146185479,9670001528699130,1,2005
340
+ 2044185039545611,3102516580176991,1,2005
341
+ 2044185039545611,3719659803766075,1,2005
342
+ 2044185039545611,4839958636560578,1,2005
343
+ 3102516580176991,3719659803766075,3,2005
344
+ 2066412407084475,7065415640299923,1,2005
345
+ 2078192817381979,3041207015099007,1,2005
346
+ 2156233396351766,7165309884613944,4,2005
347
+ 2156233396351766,5138179150855710,1,2005
348
+ 2156233396351766,9421036839649891,2,2005
349
+ 5138179150855710,7165309884613944,1,2005
350
+ 5138179150855710,9421036839649891,1,2005
351
+ 7165309884613944,9421036839649891,2,2005
352
+ 8273833711093081,9799543313637032,1,2005
353
+ 3786849380328830,8834879294274696,1,2005
354
+ 3786849380328830,6992022550781486,1,2005
355
+ 2365009826704350,6145914261746192,1,2005
356
+ 2365009826704350,6473264538281674,1,2005
357
+ 2365009826704350,7052822499655835,1,2005
358
+ 6145914261746192,6473264538281674,1,2005
359
+ 6145914261746192,7052822499655835,1,2005
360
+ 2437618029198031,4598268957554146,1,2005
361
+ 2437618029198031,9549355078296600,1,2005
362
+ 4598268957554146,9549355078296600,4,2005
363
+ 4598268957554146,6272691744956776,1,2005
364
+ 4598268957554146,6705947587249944,1,2005
365
+ 2478209414553596,3987548764592597,1,2005
366
+ 2492272869814376,3937730937800102,1,2005
367
+ 4746729271781281,9389378863874821,1,2005
368
+ 2501465557800738,4518052942799360,1,2005
369
+ 2505780539057327,3074251284380296,1,2005
370
+ 2505780539057327,6461615371964746,1,2005
371
+ 2532451941529446,4529648868442372,2,2005
372
+ 2589674716606823,5851444147973628,1,2005
373
+ 2589674716606823,9304521461975448,1,2005
374
+ 5851444147973628,9304521461975448,2,2005
375
+ 5851444147973628,9801471773565555,1,2005
376
+ 2595419593124753,8754335906813622,1,2005
377
+ 2685016201850343,8226529794937801,1,2005
378
+ 2727021833417951,6698384703955708,1,2005
379
+ 2727021833417951,8660713799152707,1,2005
380
+ 2727021833417951,8935733122024526,1,2005
381
+ 8660713799152707,8935733122024526,1,2005
382
+ 2753210204183457,9135389564267691,1,2005
383
+ 2815704284765959,8666575944280178,1,2005
384
+ 2859617428983062,3641356939660511,1,2005
385
+ 2859617428983062,4673198445813304,1,2005
386
+ 2939453694529727,7187620542811161,1,2005
387
+ 2985845109308680,2994208795860340,1,2005
388
+ 2994208795860340,4659383009804694,1,2005
389
+ 2994208795860340,4170480157675812,5,2005
390
+ 3024747722960663,8091857216878149,1,2005
391
+ 3028064067925093,8166614311904899,1,2005
392
+ 3074251284380296,5168671769851394,1,2005
393
+ 6333263003065071,6753120473010454,2,2005
394
+ 3378687696349188,6473264538281674,1,2005
395
+ 3488369448766844,4970185830248841,1,2005
396
+ 5198835715685957,6929918304117097,1,2005
397
+ 3681973868571725,3937730937800102,1,2005
398
+ 3681973868571725,6102561882464179,1,2005
399
+ 3937730937800102,6102561882464179,1,2005
400
+ 3937730937800102,7165309884613944,1,2005
401
+ 3682039423010012,8341612542504580,1,2005
402
+ 3889577781115921,9613048243963288,1,2005
403
+ 4195963292029157,7724673983792914,1,2005
404
+ 4278579756771870,8722291294149389,1,2005
405
+ 4314080541935670,5802995114126430,1,2005
406
+ 4314080541935670,9448803576146788,1,2005
407
+ 6272691744956776,6705947587249944,1,2005
408
+ 6272691744956776,9549355078296600,1,2005
409
+ 6705947587249944,9549355078296600,1,2005
410
+ 6900691363790450,7102297657290885,2,2005
411
+ 5686067626728014,8377972579342582,2,2005
412
+ 4881571012899098,5169720837544771,1,2005
413
+ 5113533258591269,8089506615068686,1,2005
414
+ 5113533258591269,9045877879972358,1,2005
415
+ 8089506615068686,9045877879972358,1,2005
416
+ 8089506615068686,9782083437466823,1,2005
417
+ 5115477440886635,5736078976141563,1,2005
418
+ 5170293352882261,7660947838427997,1,2005
419
+ 5185567045831730,6352285207676599,1,2005
420
+ 5192405148322932,8973828929584707,1,2005
421
+ 5287040686973900,6504389569181140,3,2005
422
+ 5505473483148722,7586593635931862,2,2005
423
+ 5505473483148722,8666548473150908,3,2005
424
+ 7586593635931862,8666548473150908,2,2005
425
+ 9304521461975448,9801471773565555,1,2005
426
+ 5949671653514821,8443300958745785,1,2005
427
+ 5963049225248687,8321059230428548,2,2005
428
+ 5963500663616150,7453131783140991,1,2005
429
+ 5963500663616150,7904583130708474,1,2005
430
+ 5963500663616150,8497617470595844,1,2005
431
+ 7453131783140991,7904583130708474,1,2005
432
+ 6109006373276426,7187830298420252,1,2005
433
+ 6177285003536982,8485576038579823,1,2005
434
+ 6177285003536982,9755286023695546,2,2005
435
+ 6177285003536982,6197248715251424,1,2005
436
+ 8485576038579823,9755286023695546,2,2005
437
+ 8480008508757318,8857252948439619,2,2005
438
+ 8480008508757318,9663535509009552,2,2005
439
+ 8857252948439619,9663535509009552,2,2005
440
+ 6461707333488084,7507927543005255,3,2005
441
+ 6660342017209730,9710472636673874,1,2005
442
+ 6821363733372088,9888773440748971,1,2005
443
+ 7288300876119109,9205761186706273,1,2005
444
+ 7595956670871407,9205761186706273,1,2005
445
+ 7658154224914749,9944131333164201,1,2005
446
+ 7700733161357066,7988082278299049,1,2005
447
+ 8278472628252508,9782083437466823,1,2005
@@ -0,0 +1,4 @@
1
+ source,target,weight,year
2
+ n1,n2,1,2005
3
+ n2,n3,1,2005
4
+ n3,n1,1,2005
@@ -0,0 +1,4 @@
1
+ source,target,weight,year
2
+ n1,n2,1,2005
3
+ n2,n3,1,2005
4
+ n3,n1,1,2005
@@ -0,0 +1,44 @@
1
+ require_relative '../../lib/rgraph/graph'
2
+
3
+ describe Graph do
4
+ describe "read .csv" do
5
+ subject { Graph.new('spec/fixtures/three_links.csv') }
6
+ it "creates three nodes" do
7
+ expect(subject.nodes.size).to eq(3)
8
+ end
9
+
10
+ it "creates all neighbours" do
11
+ nodes = subject.nodes[1..-1]
12
+ expect(subject.nodes.first.neighbours).to eq(nodes)
13
+ end
14
+
15
+ it "creates three links" do
16
+ expect(subject.links.size).to eq(3)
17
+ end
18
+
19
+ it "gets all nodes one by one" do
20
+ nodes = []
21
+ subject.each_node do |node|
22
+ nodes << node
23
+ end
24
+ expect(subject.nodes).to eq(nodes)
25
+ end
26
+
27
+ it "gets all links one by one" do
28
+ links = []
29
+ subject.each_link do |link|
30
+ links << link
31
+ end
32
+ expect(subject.links).to eq(links)
33
+ end
34
+
35
+ it "creates 445 links" do
36
+ expect(Graph.new('spec/fixtures/2005.csv').nodes.size).to eq(445)
37
+ end
38
+
39
+ it "creates a Graph with a not csv file" do
40
+ expect { Graph.new('spec/fixtures/2005') }.to raise_exception("the file must be a .csv")
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,39 @@
1
+ require_relative '../../lib/rgraph/link'
2
+ require_relative '../../lib/rgraph/node'
3
+
4
+
5
+ describe Link do
6
+ describe "creates a link without a weight" do
7
+ subject { Link.new(source: Node.new(id: 00001), target: Node.new(id: 00002), years: [2011, 2012]) }
8
+ its(:source) { should be_kind_of Node }
9
+ its(:target) { should be_kind_of Node }
10
+ its(:weight) { should == 1 }
11
+ its(:years) { should == [2011, 2012] }
12
+ end
13
+
14
+ describe "creates a link passing a weight" do
15
+ subject { Link.new(source: Node.new(id: 00001), target: Node.new(id: 00002), weight: 4, years: [2011, 2012]) }
16
+ its(:weight) { should == 4 }
17
+
18
+ it "checks the creation of neighbours" do
19
+ expect(subject.source.neighbours).to eq([subject.target])
20
+ expect(subject.target.neighbours).to eq([subject.source])
21
+ end
22
+ end
23
+
24
+ it "creates a link without source" do
25
+ expect { Link.new(target: Node.new(id: 00001)) }.to raise_exception("source cant be nil")
26
+ end
27
+
28
+ it "creates a link without target" do
29
+ expect { Link.new(source: Node.new(id: 00001)) }.to raise_exception("target cant be nil")
30
+ end
31
+
32
+ it "creates a link with wrong source type" do
33
+ expect { Link.new(source: "Lucas", target: Node.new(id: 1)) }.to raise_exception("source must be of type Node")
34
+ end
35
+
36
+ it "creates a link with wrong target type" do
37
+ expect { Link.new(source: Node.new(id: 1), target: "Lucas") }.to raise_exception("target must be of type Node")
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../../lib/rgraph/node'
2
+
3
+ describe Node do
4
+ describe ".new" do
5
+ subject { Node.new(name: "Lucas", node_ids: [00001, "00002", 00003], age: 20) }
6
+ its(:name) { should == "Lucas" }
7
+ its(:node_ids) { should == [00001, "00002", 00003] }
8
+ its(:age) { should == 20 }
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1 @@
1
+ require 'rgraph'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-07 00:00:00.000000000 Z
13
+ date: 2013-08-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -76,11 +76,28 @@ dependencies:
76
76
  - - ~>
77
77
  - !ruby/object:Gem::Version
78
78
  version: 3.0.2
79
+ - !ruby/object:Gem::Dependency
80
+ name: fastercsv
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 1.5.5
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 1.5.5
79
95
  description: Ruby's Graph Library
80
96
  email:
81
97
  - aride.moulin@gmail.com
82
98
  - michel@michelboaventura.com
83
- executables: []
99
+ executables:
100
+ - guard
84
101
  extensions: []
85
102
  extra_rdoc_files: []
86
103
  files:
@@ -92,9 +109,21 @@ files:
92
109
  - LICENSE
93
110
  - README.md
94
111
  - Rakefile
112
+ - bin/guard
95
113
  - lib/rgraph.rb
114
+ - lib/rgraph/graph.rb
115
+ - lib/rgraph/link.rb
116
+ - lib/rgraph/node.rb
96
117
  - lib/rgraph/version.rb
97
118
  - rgraph.gemspec
119
+ - spec/fixtures/2005.csv
120
+ - spec/fixtures/three_links.csv
121
+ - spec/fixtures/two_links.csv
122
+ - spec/rgraph/graph_spec.rb
123
+ - spec/rgraph/link_spec.rb
124
+ - spec/rgraph/node_spec.rb
125
+ - spec/rgraph/rgraph_spec.rb
126
+ - spec/spec_helper.rb
98
127
  homepage: http://github.com/akz92/rgraph
99
128
  licenses:
100
129
  - MIT
@@ -120,4 +149,12 @@ rubygems_version: 1.8.24
120
149
  signing_key:
121
150
  specification_version: 3
122
151
  summary: A Ruby's Graph Library
123
- test_files: []
152
+ test_files:
153
+ - spec/fixtures/2005.csv
154
+ - spec/fixtures/three_links.csv
155
+ - spec/fixtures/two_links.csv
156
+ - spec/rgraph/graph_spec.rb
157
+ - spec/rgraph/link_spec.rb
158
+ - spec/rgraph/node_spec.rb
159
+ - spec/rgraph/rgraph_spec.rb
160
+ - spec/spec_helper.rb