/usr/lib/ruby/1.8/rd/document-struct.rb is in librd-ruby1.8 0.6.22-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | module RD
# DocumentStructure defines and restricts structure of document tree.
# it consists of ElementRelationship
class DocumentStructure
def initialize
@relationships = []
end
def add_relationships(*relations)
@relationships += relations
end
def define_relationship(parent, child)
add_relationships(ElementRelationship.new(parent, child))
end
def each_relationship
@relationships.each do |i|
yield(i)
end
end
def is_valid?(parent, child)
each_relationship do |i|
return true if i.match?(parent, child)
end
false
end
end
# ElementRelationship is knowledge about parent-children relationship
# between Elements.
class ElementRelationship
attr_reader(:parent, :child)
def initialize(parent, child)
@parent = parent
@child = child
end
def match?(parent, child)
parent.is_a? @parent and child.is_a? @child
end
end
end
|