-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtxt_to_json.rb
executable file
·50 lines (37 loc) · 1.11 KB
/
txt_to_json.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
41
42
43
44
45
46
47
48
49
require 'rubygems'
require 'activesupport'
def to_var(s)
s.to_s.strip.downcase.underscore.gsub(/\(.*\)/,'').gsub(/[^a-z]+/,'_').gsub(/_+$/,'').strip
end
def to_label(s)
s.gsub(/\(.*\)/,'').strip
end
puts 'var nodes = {};'
puts 'var edges = {};'
columns = 9
lines = File.readlines('agile_methods.txt')
lines.shift
headers = []
columns.times { headers << lines.shift }
headers.shift
headers.each do |h|
next if h.blank?
label = to_label(h)
k = to_var(h)
puts "nodes['" + k + "'] = { label: '" + label + "', mass: 3, origin: true, cssClass: 'method'};"
end
columns.times { lines.shift }
lines.each_slice(columns) do |slice|
label = to_label(slice.shift)
next if label.blank?
next unless slice.any? {|s| !s.blank? && s.to_i < 15}
k = to_var(label)
puts "nodes['" + k + "'] = { label: '" + label + "', mass: 2, cssClass: 'attr'};"
headers.each_with_index do |header, i|
next if slice[i].blank?
wt = (slice[i].to_i * 5) + 30
wt = 80 if wt > 80
headerk = to_var(header)
puts "edges['#{headerk+k}'] = { nodeA: '#{headerk}', nodeB: '#{k}', weight: #{wt}}"
end
end