Class: Location
- Inherits:
-
Object
- Object
- Location
- Defined in:
- lib/test.rb,
lib/locator.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #get_ip ⇒ Object
- #get_zip ⇒ Object
-
#initialize ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize ⇒ Location
Returns a new instance of Location.
9 10 11 12 |
# File 'lib/locator.rb', line 9 def initialize @ip = get_ip @zip = get_zip end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
6 7 8 |
# File 'lib/test.rb', line 6 def ip @ip end |
#zip ⇒ Object
Returns the value of attribute zip.
6 7 8 |
# File 'lib/test.rb', line 6 def zip @zip end |
Instance Method Details
#get_ip ⇒ Object
8 9 10 11 12 |
# File 'lib/test.rb', line 8 def get_ip html = open('http://ipecho.net/') noko = Nokogiri::HTML(html) @ip = noko.search('h1').text.gsub("Your IP is ", "") end |
#get_zip ⇒ Object
14 15 16 |
# File 'lib/test.rb', line 14 def get_zip @zip = Geocoder.search(@ip)[0].data["zip_code"] end |