Class: Sevgi::Graphics::Element

Inherits:
Object
  • Object
show all
Extended by:
Ident
Defined in:
lib/sevgi/graphics/element.rb

Direct Known Subclasses

Document::Proto

Defined Under Namespace

Modules: Ident

Constant Summary collapse

RootParent =
Object.new.tap { |this| def this.inspect = "RootParent" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ident

id

Constructor Details

#initialize(name, attributes: {}, contents: [], parent:, &block) ⇒ Element

Returns a new instance of Element.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sevgi/graphics/element.rb', line 20

def initialize(name, attributes: {}, contents: [], parent:, &block)
  @name       = name
  @attributes = Attributes.new(attributes)
  @contents   = contents
  @parent     = parent
  @children   = []

  parent.children << self unless self.class.root?(self)

  instance_exec(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, &block) ⇒ Object



32
33
34
# File 'lib/sevgi/graphics/element.rb', line 32

def method_missing(name, *, &block)
  Element.valid?(id = Element.id(name)) ? Dispatch.(self, id, *, &block) : super
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



18
19
20
# File 'lib/sevgi/graphics/element.rb', line 18

def attributes
  @attributes
end

#childrenObject

Returns the value of attribute children.



18
19
20
# File 'lib/sevgi/graphics/element.rb', line 18

def children
  @children
end

#contentsObject (readonly)

Returns the value of attribute contents.



18
19
20
# File 'lib/sevgi/graphics/element.rb', line 18

def contents
  @contents
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/sevgi/graphics/element.rb', line 18

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



18
19
20
# File 'lib/sevgi/graphics/element.rb', line 18

def parent
  @parent
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sevgi/graphics/element.rb', line 36

def respond_to_missing?(name, include_private = false)
  Element.valid?(Element.id(name)) || super
end