Class: Parser
- Inherits:
-
FSM
show all
- Defined in:
- lib/netutils/parser.rb
Direct Known Subclasses
Alaxala::Interface, Alaxala::LLDP, Alaxala::MACFIB, Alaxala::ShowARP, Alaxala::ShowRoute, Alaxala::ShowVRF, Cisco::CDP, Cisco::IfSummary, Cisco::Interface, Cisco::MACFIB, Cisco::ShowARP, Cisco::ShowInterface, Cisco::ShowRoute, Cisco::ShowVRF
Constant Summary
Constants inherited
from FSM
FSM::FSM_S_INIT
Instance Method Summary
collapse
Methods inherited from FSM
#cb, #changeto, #state_name
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
4
5
6
7
|
# File 'lib/netutils/parser.rb', line 4
def initialize
super
@regexp = Array.new
end
|
Instance Method Details
#add(sname, cb, regexp = nil) ⇒ Object
9
10
11
12
|
# File 'lib/netutils/parser.rb', line 9
def add(sname, cb, regexp = nil)
super(sname, cb)
@regexp.push(regexp)
end
|
#parse(buf) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/netutils/parser.rb', line 20
def parse(buf)
buf.each_line do |l|
unless l.chomp! =~ regexp
raise(ArgumentError,
"No match at #{state_name}: \"#{l}\" " +
"to #{regexp.to_s}")
end
send(cb, l, $~)
end
end
|
#regexp ⇒ Object
14
15
16
17
18
|
# File 'lib/netutils/parser.rb', line 14
def regexp
r = @regexp[@state]
r = /^.*$/ if r == nil
return r
end
|