Class: RIRFinder::RIR
- Inherits:
-
Object
- Object
- RIRFinder::RIR
- Defined in:
- lib/rirfinder/rir.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_fetch(rir_list) ⇒ Object
- #_parse ⇒ Object
- #build_db ⇒ Object
-
#initialize(db, rir, tmp = '/tmp/rir') ⇒ RIR
constructor
A new instance of RIR.
Constructor Details
#initialize(db, rir, tmp = '/tmp/rir') ⇒ RIR
Returns a new instance of RIR.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rirfinder/rir.rb', line 6 def initialize db, rir, tmp = '/tmp/rir' @rir_index = [:afrinic, :apnic, :arin, :lacnic, :ripe] @db = db @rir = if rir == :all @rir_index else rir.class == Array ? rir : Array.new.push(rir) end @tmp = tmp and Dir.mkdir tmp rescue nil end |
Class Method Details
.generate(args = {db: 'rir.db', rir: :all, fetch: false}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rirfinder/rir.rb', line 45 def generate args = {db: 'rir.db', rir: :all, fetch: false} if args[:fetch] self.new(args[:db], args[:rir]).build_db else self.new(args[:db], args[:rir])._parse end end |
Instance Method Details
#_fetch(rir_list) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rirfinder/rir.rb', line 23 def _fetch rir_list rir_list.each do |rir| fp = open @tmp + "/#{rir}", 'w' fp.write HTTParty.get("http://ftp.#{rir}.net/pub/stats/#{rir}/delegated-#{rir}-extended-latest") fp.close end end |
#_parse ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rirfinder/rir.rb', line 31 def _parse reports = Hash.new ignore_initial_lines = 4 Dir.chdir @tmp (Dir.entries(@tmp) - ['.', '..']).each do |report| fp = open report reports[report] = fp.read.lines.select{|line| line[0] != '#'}[ignore_initial_lines..-1] .map{|line| line.split '|'} fp.close end reports end |
#build_db ⇒ Object
17 18 19 20 21 |
# File 'lib/rirfinder/rir.rb', line 17 def build_db _fetch @rir _parse # TODO end |