Class: CmdMatcher::LineMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/cmd_matcher.rb

Direct Known Subclasses

LineEqualer

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#matchesObject (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