Class: GmapsProxy
- Inherits:
-
Object
- Object
- GmapsProxy
- Defined in:
- lib/gmaps_proxy.rb
Constant Summary collapse
- GOOGLE_MAPS_URL =
"http://maps.google.com/?hl=iw&q="
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
Instance Method Summary collapse
- #ensure_valid_address! ⇒ Object
-
#initialize(address = "Israel") ⇒ GmapsProxy
constructor
A new instance of GmapsProxy.
- #pull ⇒ Object
- #url_with_address ⇒ Object
Constructor Details
#initialize(address = "Israel") ⇒ GmapsProxy
Returns a new instance of GmapsProxy.
11 12 13 |
# File 'lib/gmaps_proxy.rb', line 11 def initialize(address = "Israel") @address = URI.encode(address) end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
9 10 11 |
# File 'lib/gmaps_proxy.rb', line 9 def address @address end |
Instance Method Details
#ensure_valid_address! ⇒ Object
72 73 74 |
# File 'lib/gmaps_proxy.rb', line 72 def ensure_valid_address! raise EmptyAddress if (self.address.nil? || self.address.empty?) end |
#pull ⇒ Object
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gmaps_proxy.rb', line 19 def pull doc = Nokogiri::HTML(open(url_with_address)) 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 |
#url_with_address ⇒ Object
67 68 69 70 |
# File 'lib/gmaps_proxy.rb', line 67 def url_with_address ensure_valid_address! [GOOGLE_MAPS_URL,self.address].join end |