Class: Prompt::MultiMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/prompt/multi_matcher.rb

Constant Summary

Constants inherited from Matcher

Prompt::Matcher::SEP

Instance Attribute Summary

Attributes inherited from Matcher

#parameter

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from Prompt::Matcher

Instance Method Details

#matches(s) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/prompt/multi_matcher.rb', line 8

def matches s
  return [""] if s.length == 0
  ss = StringScanner.new(s)
  r = Regexp.new "[^#{SEP}]*"
  res = []
  until ss.eos?
    ss.scan /#{SEP}/
    res << ss.scan(r)
  end
  res
end

#regexObject



4
5
6
# File 'lib/prompt/multi_matcher.rb', line 4

def regex
  "(?<#{parameter.name}>([^#{SEP}]*)(#{SEP}[^#{SEP}]*)*)"
end