24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cucumber-rest-bdd/list.rb', line 24
def initialize(match)
@match = match
grouping = []
nesting = match
minimalListRegex = %r{(?:#{HAVE_ALTERNATION.split('/').join('|')})\s+(?:(a list of)\s+)?(?:a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})\s+)?(#{INT_AS_WORDS_SYNONYM}|\d+))\s+(#{FIELD_NAME_SYNONYM})}
maximalListRegex = %r{(?:#{HAVE_ALTERNATION.split('/').join('|')})\s+(?:(a list of)\s+)?(?:a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})\s+)?(#{INT_AS_WORDS_SYNONYM}|\d+))\s+(#{MAXIMAL_FIELD_NAME_SYNONYM})}
while matches = minimalListRegex.match(nesting)
nextMatches = minimalListRegex.match(nesting[matches.end(0), nesting.length])
matches = maximalListRegex.match(nextMatches.nil? ? nesting : nesting[0, matches.end(0) + nextMatches.begin(0)])
nesting = nesting[matches.end(0), nesting.length]
if matches[1].nil? then
if matches[3].nil? then
level = {
type: 'single',
key: matches[4],
root: false
}
else
level = {
type: 'multiple',
key: matches[4],
comparison: ListCountComparison.new(matches[2], matches[3]),
root: false
}
end
else
level = {
type: 'list',
key: matches[4],
comparison: ListCountComparison.new(matches[2], matches[3]),
root: false
}
end
grouping.push(level)
end
@grouping = grouping.reverse
end
|