16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/eg/net/simulator.rb', line 16
def GeoCoordinate.parse string
coordinates = string.downcase.split(/\s*([wWnNsSeE])\s*|\s/).delete_if {|it| it.size.zero?}
n = [0, 0, 0, 0, 0, 0]
i = 0
north = true; east = true
coordinates.each do |data|
c = data[0, 1] if c.between?('0', '9') or c == '-'
n[i] = data.to_f
i += 1
end
north = false if c == 's'
east = false if c == 'w'
i = 3 if i > 0 and 'nsew'.index(c)
end
lat = n[0] + n[1]/60 + n[2]/3600
lon = n[3] + n[4]/60 + n[5]/3600
GeoCoordinate.new(north ? lat : -lat, east ? lon : -lon)
end
|