vipnet_parser 0.0.5 → 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vipnet_parser.rb +58 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d834041f66023f7257a3a5a3eb3d86d3aae798ed
|
4
|
+
data.tar.gz: 12061630839986ebafb911c7b7e15926157a1a7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378f8d2f99939bef16a1d60651571ba829e097c7e998222271d6bfcfbce606be3a3aa51628ae834a14a6628d1f9e893bd75fa4d4235185c0e09e48e6cc1feff2
|
7
|
+
data.tar.gz: 31b653b65ba55eab00aa7dff8e83ff7155166b5b804b388755dc3ab696ea4527b802b1400b90a2d64fb191b32ce4a4c35edc3b13af3e9b369b2d2d06059b2e6b
|
data/lib/vipnet_parser.rb
CHANGED
@@ -7,24 +7,66 @@ class VipnetParser
|
|
7
7
|
res
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.id(
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
def self.id(args)
|
11
|
+
if args.class == String
|
12
|
+
string = args
|
13
|
+
array = Array.new
|
14
|
+
elsif args.class == Hash
|
15
|
+
string = args[:string]
|
16
|
+
array = args[:array]
|
17
|
+
threshold = args[:threshold]
|
18
|
+
end
|
19
|
+
array = [] unless array
|
20
|
+
regexps = {
|
21
|
+
/(.*)(0x[0-9a-f]{1,8}-0x[0-9a-f]{1,8})(.*)/m => method(:id_parse_variant1),
|
22
|
+
/(.*)([0-9A-F]{8})(.*)/m => method(:id_parse_variant2),
|
23
|
+
/(.*)0x([0-9a-f]{1,8})(.*)/m => method(:id_parse_variant3),
|
24
|
+
}
|
25
|
+
string_matches_anything = false
|
26
|
+
regexps.each do |regexp, callback|
|
27
|
+
if string =~ regexp && !string_matches_anything
|
28
|
+
string_matches_anything = true
|
29
|
+
array += callback.call({ string: Regexp.last_match(2), threshold: threshold })
|
30
|
+
if Regexp.last_match(1) != ""
|
31
|
+
array += VipnetParser::id({ string: Regexp.last_match(1), array: array, threshold: threshold })
|
32
|
+
end
|
33
|
+
if Regexp.last_match(3) != ""
|
34
|
+
array += VipnetParser::id({ string: Regexp.last_match(3), array: array, threshold: threshold })
|
35
|
+
end
|
18
36
|
end
|
19
|
-
return vipnet_ids
|
20
37
|
end
|
21
|
-
if
|
22
|
-
return
|
38
|
+
if string_matches_anything
|
39
|
+
return array.uniq.sort
|
40
|
+
else
|
41
|
+
return []
|
23
42
|
end
|
24
|
-
|
25
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.id_parse_variant1(args)
|
46
|
+
string = args[:string]
|
47
|
+
threshold = args[:threshold]
|
48
|
+
string =~ /0x([0-9a-f]{1,8})-0x([0-9a-f]{1,8})/
|
49
|
+
interval_begin = Regexp.last_match(1).to_i(16)
|
50
|
+
interval_end = Regexp.last_match(2).to_i(16)
|
51
|
+
return [] if interval_end < interval_begin
|
52
|
+
if threshold
|
53
|
+
return [] if interval_end - interval_begin + 1 > threshold
|
26
54
|
end
|
27
|
-
|
55
|
+
array = Array.new
|
56
|
+
(interval_end - interval_begin + 1).times do |n|
|
57
|
+
array.push("0x#{(interval_begin + n).to_s(16).rjust(8, '0')}")
|
58
|
+
end
|
59
|
+
array
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.id_parse_variant2(args)
|
63
|
+
string = args[:string]
|
64
|
+
["0x" + string.downcase]
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.id_parse_variant3(args)
|
68
|
+
string = args[:string]
|
69
|
+
["0x" + string.rjust(8, "0")]
|
28
70
|
end
|
29
71
|
|
30
72
|
def self.network(id)
|
@@ -35,6 +77,8 @@ class VipnetParser
|
|
35
77
|
end
|
36
78
|
false
|
37
79
|
end
|
80
|
+
|
81
|
+
private_class_method :id_parse_variant1, :id_parse_variant2, :id_parse_variant3
|
38
82
|
end
|
39
83
|
|
40
84
|
class Iplirconf < VipnetParser
|