Sha256: 45eb3fc5ecbc167b71e47565a33ae4e044f3a7ac69e0fa3ad263f276fb90eec6

Contents?: true

Size: 973 Bytes

Versions: 30

Compression:

Stored size: 973 Bytes

Contents

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

Version data entries

30 entries across 29 versions & 4 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-5.0.8 vendor/bundle/gems/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-5.0.5 vendor/bundle/gems/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-5.0.4 vendor/bundle/gems/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/rdtool-0.6.38/lib/rd/document-struct.rb
nishidayuya-rd2odt-0.1.1.20090701.01 lib/rd2odt/rdtool/rd/document-struct.rb
nishidayuya-rd2odt-0.1.1.20090704.01 lib/rd2odt/rdtool/rd/document-struct.rb
nishidayuya-rd2odt-0.1.1.20090706.01 lib/rd2odt/rdtool/rd/document-struct.rb
nishidayuya-rd2odt-0.1.1 lib/rd2odt/rdtool/rd/document-struct.rb
tdiary-3.2.2.20130518 vendor/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-3.2.2.20130508 vendor/rdtool-0.6.38/lib/rd/document-struct.rb
tdiary-3.2.2.20130507 vendor/rdtool-0.6.38/lib/rd/document-struct.rb
rdtool-0.6.38 lib/rd/document-struct.rb
rdtool-0.6.37 lib/rd/document-struct.rb
rdtool-0.6.36 lib/rd/document-struct.rb
rdtool-0.6.35 lib/rd/document-struct.rb
rdtool-0.6.34 lib/rd/document-struct.rb
rdtool-0.6.33 lib/rd/document-struct.rb
rdtool-0.6.32 lib/rd/document-struct.rb