iosparse 0.0.5 → 0.0.6

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. data/iosparse.gemspec +2 -2
  2. data/lib/iosparse.rb +19 -11
  3. metadata +2 -2
data/iosparse.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "iosparse"
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
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"]
9
- s.date = "2013-05-02"
9
+ s.date = "2013-05-05"
10
10
  s.description = "Parse Cisco IOS configurations"
11
11
  s.email = "codemunchies@gmail.com"
12
12
  s.files = ["lib/iosparse.rb", "iosparse.gemspec", "Gemfile", "README.md"]
data/lib/iosparse.rb CHANGED
@@ -29,7 +29,7 @@ class IOSParse
29
29
  # Regex to parse out interfaces
30
30
  interfaces = /\["interface[\s\S]+/
31
31
  # Call find_blocks() passing regex, parent name, and parse boolean
32
- find_blocks(interfaces, "interface", false)
32
+ find_blocks(interfaces, "interface", false, false)
33
33
  end
34
34
 
35
35
  #
@@ -39,7 +39,7 @@ class IOSParse
39
39
  # Regex to parse out the monitor interfaces
40
40
  interfaces = /monitor-interface.+/
41
41
  # Call find_lines() passing regex, parent name, and parse boolean
42
- find_lines(interfaces, "monitor-interface", false)
42
+ find_lines(interfaces, "monitor-interface", false, true)
43
43
  end
44
44
 
45
45
  #
@@ -49,7 +49,7 @@ class IOSParse
49
49
  # Regex to parse out names
50
50
  names = /\["names[\s\S]+/
51
51
  # Call find_blocks() passing regex, parent name, and parse boolean
52
- find_blocks(names, "names", false)
52
+ find_blocks(names, "names", false, false)
53
53
  end
54
54
 
55
55
  #
@@ -59,7 +59,7 @@ class IOSParse
59
59
  # Regex to parse out routes
60
60
  routes = /\["route[\s\S]+/
61
61
  # Call find_blocks() passing regex, parent name, and parse boolean
62
- find_blocks(routes, "route", false)
62
+ find_blocks(routes, "route", false, false)
63
63
  end
64
64
 
65
65
  #
@@ -69,7 +69,7 @@ class IOSParse
69
69
  # Regex to parse out acl
70
70
  acl = /access-list[\s\S]+/
71
71
  # Call find_blocks() passing regex, parent name, and parse boolean
72
- find_blocks(acl, "access-list", true)
72
+ find_blocks(acl, "access-list", true, true)
73
73
  end
74
74
 
75
75
  #
@@ -79,7 +79,7 @@ class IOSParse
79
79
  # Regex to parse out object-groups
80
80
  group = /object-group[\s\S]+/
81
81
  # Call find_blocks() passing regex, parent name, and parse boolean
82
- find_blocks(group, "object-group", true)
82
+ find_blocks(group, "object-group", true, true)
83
83
  end
84
84
 
85
85
  private
@@ -87,15 +87,19 @@ class IOSParse
87
87
  #
88
88
  # Primary method to accept regex and parent, then use them to parse blocks and store them in an Array
89
89
  #
90
- def find_blocks(filter, parent, parse)
90
+ def find_blocks(filter, parent, parse, normalize)
91
91
  # Array to store parsed blocks
92
92
  output = Array.new
93
93
  @blocks.each do |block|
94
94
  # Use regex to filter via scan() and flatten then push to array
95
- output << normalize_block(block.to_s.scan(filter).flatten) if block.to_s.include?(parent)
95
+ if normalize then
96
+ output << normalize_block(block.to_s.scan(filter).flatten) if block.to_s.include?(parent)
97
+ else
98
+ output << block.to_s.scan(filter).flatten if block.to_s.include?(parent)
99
+ end
96
100
  end
97
101
  # Some parents are not within "!" blocks and require some extra work
98
- if parse == true then
102
+ if parse then
99
103
  parse_parent(clean_parent(output), parent)
100
104
  else
101
105
  # Return the parsed block as an array
@@ -106,7 +110,7 @@ class IOSParse
106
110
  #
107
111
  # Primary method to accept regex and parent, then use them to parse lines and store them in an Array
108
112
  #
109
- def find_lines(filter, parent, parse)
113
+ def find_lines(filter, parent, parse, normalize)
110
114
  # Array to store parsed blocks
111
115
  output = Array.new
112
116
  @blocks.each do |block|
@@ -115,7 +119,11 @@ class IOSParse
115
119
  # Skip unless the parent is in the line
116
120
  next unless line.match(filter)
117
121
  # Push matches to array and normalize the matched lines
118
- output << normalize_line(line.match(filter))
122
+ if normalize then
123
+ output << normalize_line(line.match(filter))
124
+ else
125
+ output << line.match(filter)
126
+ end
119
127
  end
120
128
  end
121
129
  # 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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Parse Cisco IOS configurations
15
15
  email: codemunchies@gmail.com