3
# DocumentStructure defines and restricts structure of document tree.
4
# it consists of ElementRelationship
5
class DocumentStructure
10
def add_relationships(*relations)
11
@relationships += relations
14
def define_relationship(parent, child)
15
add_relationships(ElementRelationship.new(parent, child))
19
@relationships.each do |i|
24
def is_valid?(parent, child)
25
each_relationship do |i|
26
return true if i.match?(parent, child)
32
# ElementRelationship is knowledge about parent-children relationship
34
class ElementRelationship
35
attr_reader(:parent, :child)
37
def initialize(parent, child)
42
def match?(parent, child)
43
parent.is_a? @parent and child.is_a? @child