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
|
# File 'lib/octranspo/landmarks.rb', line 10
def find_landmarks_surrounding (query)
query = simplify_accented_characters_in(query)
url = URI.parse('http://www.octranspo.com/maps/busstops/imap.asp')
params = {"address" => query, "page"=>"search"}
response = Net::HTTP.post_form(url, params)
chunks = response.body.split("var marker = createMarker(new GPoint").map do |chunk|
chunk.strip.sub(");\r\nmap.addOverlay(marker);", '')
end
chunks.shift
chunks.pop
chunks.map do |chunk|
results = {}
first_part, second_part = chunk.split("\"").compact
latitude, longitude = first_part.sub("(", '').sub('), ', '').split(", ")
results.merge!(:latitude => latitude, :longitude => longitude)
results[:number] = Array(/INFO_PHONE=(\d\d\d\d)/.match(second_part))[1]
if id_matches = /<small> \(([A-Z0-9]+)\)<\/small>/.match(second_part)
results[:id] = id_matches[1]
end
if detour_matches = / - Detour<br><\/span>/.match(second_part)
results[:temporary?] = true
end
results
end
end
|