Class: RD::DocumentStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/rd/document-struct.rb,
lib/rd/rd-struct.rb,
lib/rd/loose-struct.rb

Overview

DocumentStructure defines and restricts structure of document tree. it consists of ElementRelationship

Constant Summary collapse

RD =
DocumentStructure.new
LOOSE =
DocumentStructure.new

Instance Method Summary collapse

Constructor Details

#initializeDocumentStructure

Returns a new instance of DocumentStructure.



6
7
8
# File 'lib/rd/document-struct.rb', line 6

def initialize
  @relationships = []
end

Instance Method Details

#add_relationships(*relations) ⇒ Object



10
11
12
# File 'lib/rd/document-struct.rb', line 10

def add_relationships(*relations)
  @relationships += relations
end

#define_relationship(parent, child) ⇒ Object



14
15
16
# File 'lib/rd/document-struct.rb', line 14

def define_relationship(parent, child)
  add_relationships(ElementRelationship.new(parent, child))
end

#each_relationshipObject



18
19
20
21
22
# File 'lib/rd/document-struct.rb', line 18

def each_relationship
  @relationships.each do |i|
	yield(i)
  end
end

#is_valid?(parent, child) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/rd/document-struct.rb', line 24

def is_valid?(parent, child)
  each_relationship do |i|
	return true if i.match?(parent, child)
  end
  false
end