class ListNesting

Handle many children within objects or lists

Attributes

grouping[R]
match[R]

Public Class Methods

new(match) click to toggle source
# File lib/cucumber-rest-bdd/list.rb, line 28
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

  minimal_list = /(?:#{HAVE_ALTERNATION.split('/').join('|')})?\s*
                 (?:(a\slist\sof)\s+)?(?:a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})
                 \s+)?(#{INT_AS_WORDS_SYNONYM}|\d+))\s+
                 (#{FIELD_NAME_SYNONYM})/x
  maximal_list = /(?:#{HAVE_ALTERNATION.split('/').join('|')})?\s*
                 (?:(a\slist\sof)\s+)?(?:a|an|(?:(#{FEWER_MORE_THAN_SYNONYM})
                 \s+)?(#{INT_AS_WORDS_SYNONYM}|\d+))\s+
                 (#{MAXIMAL_FIELD_NAME_SYNONYM})/x
  while (matches = minimal_list.match(nesting))
    next_matches = minimal_list.match(nesting[matches.end(0), nesting.length])
    to_match = if next_matches.nil?
                 nesting
               else
                 nesting[0, matches.end(0) + next_matches.begin(0)]
               end
    matches = maximal_list.match(to_match)
    nesting = nesting[matches.end(0), nesting.length]

    level = if matches[1].nil?
              if matches[3].nil?
                {
                  type: 'single',
                  key: matches[4],
                  root: false
                }
              else
                {
                  type: 'multiple',
                  key: matches[4],
                  comparison: ListCountComparison.new(matches[2], matches[3]),
                  root: false
                }
              end
            else
              {
                type: 'list',
                key: matches[4],
                comparison: ListCountComparison.new(matches[2], matches[3]),
                root: false
              }
            end
    grouping.push(level)
  end
  @grouping = grouping.reverse
end

Public Instance Methods

push(node) click to toggle source
# File lib/cucumber-rest-bdd/list.rb, line 81
def push(node)
  @grouping.push(node)
end