Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed and tested (manually
  • Loading branch information
Elad Meidar committed Jan 31, 2010
1 parent 3d2d1b4 commit dc8c6db
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions lib/gmaps_proxy.rb
Expand Up @@ -6,17 +6,62 @@ class EmptyAddress < StandardError; end
class GmapsProxy

GOOGLE_MAPS_URL = "http://maps.google.com/?hl=iw&q="
attr_accessible :address
attr_accessor :address

def initialize(address = "Israel")
@address = "Israel"
@address = URI.encode(address)
end

def address=(new_address)
self.address = URI.encode(address)
end

protected

def pull
doc = Nokogiri::HTML(open(url_with_address))
tiles = doc.at_css("#inlineTiles")
image_tiles = doc.search("#inlineTiles img")

table = ""

table << "<tr>"
count = 0
image_tiles.each do |image_node|



table << "<td><img src='#{image_node['src']}'/></td>"

count += 1
if count == 2
table << "</tr>"
table << "<tr>"
count = 0
end
end
table << "</tr>"

output =<<-EOS
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8" />
<title>GoogleMaps Proxy</title>
<style>
* { margin:0; padding:0;, line-height:0; }
div {
border:0;
background:red;
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
#{table}
</table>
</body>
</html>
EOS

return output

end

def url_with_address
Expand All @@ -25,6 +70,6 @@ def url_with_address
end

def ensure_valid_address!
raise EmptyAddress if (self.address.nil? || self.address.blank?)
raise EmptyAddress if (self.address.nil? || self.address.empty?)
end
end

0 comments on commit dc8c6db

Please sign in to comment.