Class: Hvor::IPRange
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Hvor::IPRange
- Defined in:
- app/models/hvor/ip_range.rb
Class Method Summary collapse
Class Method Details
.find_containing(ip) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/hvor/ip_range.rb', line 9 def self.find_containing(ip) normalized = Hvor::IpNormalizer.normalize(ip) from_column, to_column = normalized.version == :ipv4 ? %w[ipv4_from ipv4_to] : %w[ipv6_from ipv6_to] range = where(ip_version: normalized.version) .where("#{from_column} <= ?", normalized.value) .order(from_column => :desc) .first range if range && range[to_column] && range[to_column] >= normalized.value end |
.lookup_country_code(ip) ⇒ Object
5 6 7 |
# File 'app/models/hvor/ip_range.rb', line 5 def self.lookup_country_code(ip) find_containing(ip)&.country_code end |