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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vipnet_parser.rb +58 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 412976a93107392b94f27890186cc98f02930536
4
- data.tar.gz: 1717777e8beb43cd21e4853011b3901dffd38e48
3
+ metadata.gz: d834041f66023f7257a3a5a3eb3d86d3aae798ed
4
+ data.tar.gz: 12061630839986ebafb911c7b7e15926157a1a7c
5
5
  SHA512:
6
- metadata.gz: f242154edba17fce0881e5a9647ead0282ab7be9847f7c0544e3e98cf7b5406035b2a1c2beade5fac983c530e53b0980194c2eee528fea28c524a9e74126b396
7
- data.tar.gz: 1b90c4dacb6b683cb2944d146f85ca89833e794d571f0d8e7212e0557d37b66cca632b1c15be9d6cec8583af324e19fc93d98a6914346cb05cc1ccdedc1fe8ef
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(string)
11
- if string =~ /(.*)0x([0-9a-f]{1,8})-0x([0-9a-f]{1,8})(.*)/
12
- interval_begin = Regexp.last_match(2).to_i(16)
13
- interval_end = Regexp.last_match(3).to_i(16)
14
- return [] if interval_end < interval_begin
15
- vipnet_ids = Array.new
16
- (interval_end - interval_begin + 1).times do |n|
17
- vipnet_ids.push("0x#{(interval_begin + n).to_s(16).rjust(8, '0')}")
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 string =~ /(.*)([0-9A-F]{8})(.*)/
22
- return ["0x" + Regexp.last_match(2).downcase]
38
+ if string_matches_anything
39
+ return array.uniq.sort
40
+ else
41
+ return []
23
42
  end
24
- if string =~ /(.*)0x([0-9a-f]{1,8})(.*)/
25
- return ["0x" + Regexp.last_match(2).to_s.rjust(8, "0")]
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
- false
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vipnet_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Morozov