iosparse 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/iosparse.gemspec +1 -1
  2. data/lib/iosparse.rb +31 -21
  3. metadata +1 -1
data/iosparse.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "iosparse"
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ari Mizrahi"]
data/lib/iosparse.rb CHANGED
@@ -16,13 +16,13 @@ class IOSParse
16
16
  end
17
17
 
18
18
  #
19
- # Find the interfaces in the configuration file
19
+ # Find all interfaces in the configuration file
20
20
  #
21
21
  def interfaces
22
22
  # Regex to parse out interfaces
23
23
  interfaces = /\["interface[\s\S]+/
24
- # Call findblocks() passing the regex and parent
25
- findblocks(interfaces, "interface")
24
+ # Call findblocks() passing regex, parent name, and parse boolean
25
+ findblocks(interfaces, "interface", false)
26
26
  end
27
27
 
28
28
  #
@@ -31,8 +31,18 @@ class IOSParse
31
31
  def names
32
32
  # Regex to parse out names
33
33
  names = /\["names[\s\S]+/
34
- # Call findblocks() passing regex and parent
35
- findblocks(names, "names")
34
+ # Call findblocks() passing regex, parent name, and parse boolean
35
+ findblocks(names, "names", false)
36
+ end
37
+
38
+ #
39
+ # Find all routes
40
+ #
41
+ def routes
42
+ # Regex to parse out routes
43
+ routes = /\["route[\s\S]+/
44
+ # Call findblocks() passing regex, parent name, and parse boolean
45
+ findblocks(routes, "route", false)
36
46
  end
37
47
 
38
48
  #
@@ -40,19 +50,19 @@ class IOSParse
40
50
  #
41
51
  def access_list
42
52
  # Regex to parse out acl
43
- acl = /\["access-list[\s\S]+/
44
- # Call findblocks() passing regex and parent
45
- findblocks(acl, "access-list")
53
+ acl = /access-list[\s\S]+/
54
+ # Call findblocks() passing regex, parent name, and parse boolean
55
+ findblocks(acl, "access-list", true)
46
56
  end
47
57
 
48
58
  #
49
- # Find all objects-groups
59
+ # Find all object-groups
50
60
  #
51
61
  def object_group
52
62
  # Regex to parse out object-groups
53
63
  group = /object-group[\s\S]+/
54
- # Call findblocks() passing regex and parent
55
- findblocks(group, "object-group")
64
+ # Call findblocks() passing regex, parent name, and parse boolean
65
+ findblocks(group, "object-group", true)
56
66
  end
57
67
 
58
68
  private
@@ -60,16 +70,16 @@ class IOSParse
60
70
  #
61
71
  # Primary method to accept regex and parent, then use them to parse blocks and store them in an Array
62
72
  #
63
- def findblocks(filter, parent)
73
+ def findblocks(filter, parent, parse = true)
64
74
  # Array to store parsed blocks
65
75
  output = Array.new
66
76
  @blocks.each do |block|
67
77
  # Use regex to filter via scan() and flatten then push to array
68
78
  output << block.to_s.scan(filter).flatten if block.to_s.include?(parent)
69
79
  end
70
- # Object-groups are not within "!" blocks and require some extra work
71
- if parent == "object-group" then
72
- parse_object_group(clean_object_group(output))
80
+ # Some parents are not within "!" blocks and require some extra work
81
+ if parse == true then
82
+ parse_parent(clean_object_group(output), parent)
73
83
  else
74
84
  # Return the parsed block as an array
75
85
  output
@@ -91,20 +101,20 @@ class IOSParse
91
101
  end
92
102
 
93
103
  #
94
- # Object-groups come as a single string, we break each object-group into a string and push into an array
104
+ # Some parents come as a single string, we break each parents into a string and push into an array
95
105
  #
96
- def parse_object_group(block)
106
+ def parse_parent(block, parent)
97
107
  # Array to store parsed blocks
98
108
  output = Array.new
99
109
  block.each do |line|
100
- # Split the line where each object-group begins
101
- line.to_s.split("object-group").each do |push|
110
+ # Split the line where each parent begins
111
+ line.to_s.split(parent).each do |push|
102
112
  # Skip empty lines
103
113
  next if push.include?('["')
104
114
  # Remove extra "] characters from each line
105
115
  push = push.gsub('"]', '')
106
- # Re-add object-group to the beginning of the line and push it into the array line-by-line
107
- output << "[\"object-group#{push}\"]"
116
+ # Re-add parent to the beginning of the line and push it into the array line-by-line
117
+ output << "[\"#{parent}#{push}\"]"
108
118
  end
109
119
  end
110
120
  # Return the parsed block as an array
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iosparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: