~ubuntu-branches/ubuntu/wily/tdiary/wily

« back to all changes in this revision

Viewing changes to vendor/rdtool-0.6.33/lib/rd/document-struct.rb

  • Committer: Package Import Robot
  • Author(s): Hideki Yamane
  • Date: 2013-05-19 16:14:01 UTC
  • mfrom: (12.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130519161401-hf5oyr8g8a94fsew
Tags: 3.2.2-2
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
module RD
3
 
  # DocumentStructure defines and restricts structure of document tree.
4
 
  # it consists of ElementRelationship
5
 
  class DocumentStructure
6
 
    def initialize
7
 
      @relationships = []
8
 
    end
9
 
    
10
 
    def add_relationships(*relations)
11
 
      @relationships += relations
12
 
    end
13
 
 
14
 
    def define_relationship(parent, child)
15
 
      add_relationships(ElementRelationship.new(parent, child))
16
 
    end
17
 
 
18
 
    def each_relationship
19
 
      @relationships.each do |i|
20
 
        yield(i)
21
 
      end
22
 
    end
23
 
 
24
 
    def is_valid?(parent, child)
25
 
      each_relationship do |i|
26
 
        return true if i.match?(parent, child)
27
 
      end
28
 
      false
29
 
    end
30
 
  end
31
 
 
32
 
  # ElementRelationship is knowledge about parent-children relationship
33
 
  # between Elements.
34
 
  class ElementRelationship
35
 
    attr_reader(:parent, :child)
36
 
 
37
 
    def initialize(parent, child)
38
 
      @parent = parent
39
 
      @child = child
40
 
    end
41
 
 
42
 
    def match?(parent, child)
43
 
      parent.is_a? @parent and child.is_a? @child
44
 
    end
45
 
  end
46
 
end