Class: ListNesting

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber-rest-bdd/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(match) ⇒ ListNesting

Returns a new instance of ListNesting.



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
    # gets an array in the nesting format that nest_match_attributes understands to interrogate nested object and array data
    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

Instance Method Details

#groupingObject



73
74
75
# File 'lib/cucumber-rest-bdd/list.rb', line 73

def grouping
    @grouping
end

#matchObject



69
70
71
# File 'lib/cucumber-rest-bdd/list.rb', line 69

def match
    return @match
end

#push(node) ⇒ Object



65
66
67
# File 'lib/cucumber-rest-bdd/list.rb', line 65

def push(node)
    @grouping.push(node)
end