-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.rb
40 lines (36 loc) · 971 Bytes
/
loader.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'json'
class Loader
def initialize(coordinates_path, connections_path)
@coordinates_path = coordinates_path
@connections_path = connections_path
end
def nodes
coordinates.map do |segment|
segment.keys
end
end
def coordinates
@coordinates ||= JSON.parse(File.read('coordinates.json'))
end
def connections
data = JSON.parse(File.read('connections.json'))
data.each_with_index.map do |segment, segment_idx|
segment.map do |edge|
from_name = edge['from']
to_name = edge['to']
{
'from' => {
'name' => from_name,
'x' => coordinates[segment_idx][from_name]['x'],
'y' => coordinates[segment_idx][from_name]['y']
},
'to' => {
'name' => to_name,
'x' => coordinates[segment_idx][to_name]['x'],
'y' => coordinates[segment_idx][to_name]['y']
}
}
end
end
end
end