Class: Locality::IP
- Inherits:
-
Object
- Object
- Locality::IP
- Defined in:
- lib/locality/ip.rb
Class Method Summary collapse
Instance Method Summary collapse
- #city_name ⇒ Object
- #coordinates ⇒ Object
- #country_name ⇒ Object
- #human_readable_location ⇒ Object
-
#initialize(raw_ip) ⇒ IP
constructor
A new instance of IP.
- #ip ⇒ Object
- #latitude ⇒ Object
- #longitude ⇒ Object
- #province_name ⇒ Object
- #state_name ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(raw_ip) ⇒ IP
Returns a new instance of IP.
13 14 15 |
# File 'lib/locality/ip.rb', line 13 def initialize(raw_ip) @raw_ip = raw_ip end |
Class Method Details
Instance Method Details
#city_name ⇒ Object
65 66 67 68 69 |
# File 'lib/locality/ip.rb', line 65 def city_name return unless lookup lookup.city.presence rescue => exception end |
#coordinates ⇒ Object
47 48 49 50 51 |
# File 'lib/locality/ip.rb', line 47 def coordinates return unless lookup lookup.coordinates.presence rescue => exception end |
#country_name ⇒ Object
83 84 85 86 87 |
# File 'lib/locality/ip.rb', line 83 def country_name return unless lookup lookup.country.presence rescue => exception end |
#human_readable_location ⇒ Object
43 44 45 |
# File 'lib/locality/ip.rb', line 43 def human_readable_location city_name || province_name || state_name || country_name end |
#ip ⇒ Object
37 38 39 40 41 |
# File 'lib/locality/ip.rb', line 37 def ip @ip ||= ::IPAddr.new(raw_ip.to_s) rescue => exception nil end |
#latitude ⇒ Object
53 54 55 56 57 |
# File 'lib/locality/ip.rb', line 53 def latitude return unless lookup lookup.latitude.presence rescue => exception end |
#longitude ⇒ Object
59 60 61 62 63 |
# File 'lib/locality/ip.rb', line 59 def longitude return unless lookup lookup.longitude.presence rescue => exception end |
#province_name ⇒ Object
71 72 73 74 75 |
# File 'lib/locality/ip.rb', line 71 def province_name return unless lookup lookup.province.presence rescue => exception end |
#state_name ⇒ Object
77 78 79 80 81 |
# File 'lib/locality/ip.rb', line 77 def state_name return unless lookup lookup.state.presence rescue => exception end |
#to_hash ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locality/ip.rb', line 26 def to_hash { ip: ip.to_s, city_name: city_name, province_name: province_name, state_name: state_name, country_name: country_name, human_readable_location: human_readable_location, } end |