Class: RD::DocumentStructure
- Inherits:
-
Object
- Object
- RD::DocumentStructure
- 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
Instance Method Summary collapse
- #add_relationships(*relations) ⇒ Object
- #define_relationship(parent, child) ⇒ Object
- #each_relationship ⇒ Object
-
#initialize ⇒ DocumentStructure
constructor
A new instance of DocumentStructure.
- #is_valid?(parent, child) ⇒ Boolean
Constructor Details
#initialize ⇒ DocumentStructure
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_relationship ⇒ Object
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
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 |