Module: Duxml::ChildrenRule

Included in:
ChildrenRuleClass
Defined in:
lib/duxml/meta/grammar/rule/children_rule.rb,
lib/duxml/meta/grammar/rule/children_rule.rb

Overview

class ChildrenRuleClass

Instance Method Summary collapse

Instance Method Details

#applies_to?(change_or_pattern) ⇒ Boolean

Returns whether subjects agree, and change or pattern is not a Rule and responds to #affected_parent.

Parameters:

Returns:

  • (Boolean)

    whether subjects agree, and change or pattern is not a Rule and responds to #affected_parent



53
54
55
56
57
58
59
60
61
# File 'lib/duxml/meta/grammar/rule/children_rule.rb', line 53

def applies_to?(change_or_pattern)
  case
    when change_or_pattern.is_a?(Duxml::Rule) then false
    when super(change_or_pattern) && change_or_pattern.respond_to?(:parent)
      true
    else
      false
  end
end

#qualify(change_or_pattern) ⇒ Boolean

Returns whether or not change_or_pattern#subject is allowed to have #object as its child if false, Error is reported to History.

Parameters:

Returns:

  • (Boolean)

    whether or not change_or_pattern#subject is allowed to have #object as its child if false, Error is reported to History



35
36
37
38
39
40
41
# File 'lib/duxml/meta/grammar/rule/children_rule.rb', line 35

def qualify(change_or_pattern)
  @object = change_or_pattern
  result = pass
  super change_or_pattern unless result
  @object = nil
  result
end

#required_childrenArray[String]

Returns in order, array of child doc types required by this rule.

Returns:

  • (Array[String])

    in order, array of child doc types required by this rule



44
45
46
47
48
49
# File 'lib/duxml/meta/grammar/rule/children_rule.rb', line 44

def required_children
  req_scans = get_scanners.select do |scanner| scanner[:operator].match(/[\*\?]/).nil? end
  req_scans.collect do |req_scan|
    get_child_name req_scan unless get_child_name(req_scan) == 'EMPTY'
  end.compact
end