28 lines
678 B
Ruby
28 lines
678 B
Ruby
require 'ipaddr'
|
|
|
|
module JamRuby
|
|
class JamIsp < ActiveRecord::Base
|
|
|
|
self.table_name = 'jamisp'
|
|
|
|
def self.ip_to_num(ip_addr)
|
|
i = IPAddr.new(ip_addr)
|
|
return i.to_i if i.ipv4?
|
|
nil
|
|
end
|
|
|
|
def self.lookup(ipnum)
|
|
JamIsp.select(:coid)
|
|
.where('geom && ST_MakePoint(?, 0) AND ? BETWEEN beginip AND endip', ipnum, ipnum)
|
|
.limit(1)
|
|
.first
|
|
end
|
|
|
|
def self.createx(beginip, endip, coid)
|
|
c = connection.raw_connection
|
|
c.exec_params('insert into jamisp (beginip, endip, coid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))',
|
|
[beginip, endip, coid])
|
|
end
|
|
end
|
|
end
|