class PinPoint::IpBlock
Public Class Methods
for_ip(ip)
click to toggle source
# File lib/pin_point/ip_block.rb, line 22 def for_ip ip val = ip_to_int ip maybe = where( :range_low.lte => val ).order_by( [[:range_low, :desc]] ).first if maybe.try( :range_high ).to_i >= val return maybe end nil end
Private Class Methods
ip_to_int(ip)
click to toggle source
# File lib/pin_point/ip_block.rb, line 33 def ip_to_int ip val = 0 ip.split( "." ).inject( 3 ) do |exp, octet| val += (octet.to_i * (256 ** exp)) next exp - 1 end val end