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
12 13 14 |
# File 'lib/locality/ip.rb', line 12 def initialize(raw_ip) @raw_ip = raw_ip end |
Class Method Details
.check! ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/locality/ip.rb', line 16 def self.check! if Locality.config.maxmind_geoip2_path.blank? fail end # Just checking to see if it causes any trouble notiications, but not depending on it new('8.8.8.8').country_name end |
Instance Method Details
#city_name ⇒ Object
64 65 66 67 68 |
# File 'lib/locality/ip.rb', line 64 def city_name return unless lookup lookup.city.presence rescue => exception end |
#coordinates ⇒ Object
46 47 48 49 50 |
# File 'lib/locality/ip.rb', line 46 def coordinates return unless lookup lookup.coordinates.presence rescue => exception end |
#country_name ⇒ Object
82 83 84 85 86 |
# File 'lib/locality/ip.rb', line 82 def country_name return unless lookup lookup.country.presence rescue => exception end |
#human_readable_location ⇒ Object
42 43 44 |
# File 'lib/locality/ip.rb', line 42 def human_readable_location city_name || province_name || state_name || country_name end |
#ip ⇒ Object
36 37 38 39 40 |
# File 'lib/locality/ip.rb', line 36 def ip @ip ||= ::IPAddr.new(raw_ip.to_s) rescue => exception nil end |
#latitude ⇒ Object
52 53 54 55 56 |
# File 'lib/locality/ip.rb', line 52 def latitude return unless lookup lookup.latitude.presence rescue => exception end |
#longitude ⇒ Object
58 59 60 61 62 |
# File 'lib/locality/ip.rb', line 58 def longitude return unless lookup lookup.longitude.presence rescue => exception end |
#province_name ⇒ Object
70 71 72 73 74 |
# File 'lib/locality/ip.rb', line 70 def province_name return unless lookup lookup.province.presence rescue => exception end |
#state_name ⇒ Object
76 77 78 79 80 |
# File 'lib/locality/ip.rb', line 76 def state_name return unless lookup lookup.state.presence rescue => exception end |
#to_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/locality/ip.rb', line 25 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 |