Class: Jetel::Modules::Ip
Instance Attribute Summary
Attributes inherited from Module
#downloader
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Module
#download_dir, download_dir, #download_source, downloaded_file, #downloaded_file, extract_dir, #extract_dir, extracted_file, #extracted_file, #initialize, #load, #sources, target_dir, #target_dir, #transform_dir, transform_dir, transformed_file, #transformed_file, #unzip
Class Method Details
.sources ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/jetel/modules/ip/ip.rb', line 34
def sources
[
{
name: 'afrinic',
url: 'ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest'
},
{
name: 'apnic',
url: 'ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest'
},
{
name: 'arin',
url: 'ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest'
},
{
name: 'lacnic',
url: 'ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest'
},
{
name: 'ripencc',
url: 'ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-latest'
},
{
name: 'iana',
url: 'ftp://ftp.apnic.net/pub/stats/iana/delegated-iana-latest'
}
]
end
|
Instance Method Details
#download(global_options, options, args) ⇒ Object
64
65
66
67
68
|
# File 'lib/jetel/modules/ip/ip.rb', line 64
def download(global_options, options, args)
self.class.sources.pmap do |source|
download_source(source, global_options.merge(options))
end
end
|
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/jetel/modules/ip/ip.rb', line 70
def (global_options, options, args)
self.class.sources.pmap do |source|
downloaded_file = downloaded_file(source, global_options.merge(options))
dest_dir = (source, global_options.merge(options))
puts "Extracting #{downloaded_file}"
FileUtils.mkdir_p(dest_dir)
FileUtils.cp(downloaded_file, dest_dir)
end
end
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/jetel/modules/ip/ip.rb', line 82
def transform(global_options, options, args)
self.class.sources.pmap do |source|
opts = global_options.merge(options)
= (source, opts)
transformed_file = transformed_file(source, opts)
FileUtils.mkdir_p(transform_dir(source, opts))
csv_opts = {
:col_sep => '|'
}
puts "Transforming #{}"
CSV.open(, 'r', csv_opts) do |csv|
= %w(
registry
cc
type
start
value
date
status
)
CSV.open(transformed_file, 'w', :write_headers => true, :headers => ) do |csv_out|
csv.each do |row|
next if row.length < 7
next if row[0] != source[:name]
csv_out << row
end
end
end
end
end
|