107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/construqt/util.rb', line 107
def self.createRangeDefinition(ports)
ranges=[]
lastPort=nil
ports.uniq.sort do |l,r|
fc = l.to_s.length <=> r.to_s.length
fc!=0 ? fc : l<=>r
end.each do |port|
port = port.to_s
if (ranges.length>0 && portNeighbors?(port, ranges[ranges.length-1]["to"]))
ranges[ranges.length-1]["to"] = port
else
ranges << {"from" => port, "to" => port}
end
end
ranges = ranges.map do |range|
range["from"] == range["to"] ? range["from"] : range["from"] +"-"+range["to"]
end
ranges.join(",")
end
|