Class: Location

Inherits:
Object
  • Object
show all
Defined in:
lib/test.rb,
lib/locator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocation

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

#ipObject

Returns the value of attribute ip.



6
7
8
# File 'lib/test.rb', line 6

def ip
  @ip
end

#zipObject

Returns the value of attribute zip.



6
7
8
# File 'lib/test.rb', line 6

def zip
  @zip
end

Instance Method Details

#get_ipObject



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_zipObject



14
15
16
# File 'lib/test.rb', line 14

def get_zip
  @zip = Geocoder.search(@ip)[0].data["zip_code"]
end