Module: TimezoneDetection::IpConvertion
- Included in:
- IpTimezone
- Defined in:
- lib/timezone_detection/ip_convertion.rb
Instance Method Summary collapse
Instance Method Details
#ip2long(ip) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/timezone_detection/ip_convertion.rb', line 3 def ip2long(ip) long = 0 ip.split(/\./).each_with_index do |b, i| long += b.to_i << ( 8*i ) end long end |
#long2ip(long) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/timezone_detection/ip_convertion.rb', line 11 def long2ip(long) ip = [] 4.times do |i| ip.push(long.to_i & 255) long = long.to_i >> 8 end ip.join(".") end |