Class: CmdMatcher::LineMatcher
- Inherits:
-
Object
- Object
- CmdMatcher::LineMatcher
- Defined in:
- lib/cmd_matcher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Instance Method Summary collapse
-
#initialize(matcher, opt = {}) ⇒ LineMatcher
constructor
A new instance of LineMatcher.
- #match(line) ⇒ Object
Constructor Details
#initialize(matcher, opt = {}) ⇒ LineMatcher
Returns a new instance of LineMatcher.
28 29 30 31 32 |
# File 'lib/cmd_matcher.rb', line 28 def initialize(matcher, opt = {}) @names = opt[:names] || [] @matcher = matcher @matches = nil end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
27 28 29 |
# File 'lib/cmd_matcher.rb', line 27 def matches @matches end |
Instance Method Details
#match(line) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/cmd_matcher.rb', line 34 def match(line) m = line.match(@matcher) return false unless m @matches = {} @names.each_with_index {|name, index| @matches[name] = m[index + 1] } return true end |