Class: Sevgi::Graphics::Element
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Element
- Extended by:
- Ident
- Defined in:
- lib/sevgi/graphics/element.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Ident
Constant Summary collapse
- RootParent =
Object.new.tap { def it.inspect = "RootParent" }.freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, parent:, attributes: {}, contents: [], &block) ⇒ Element
constructor
A new instance of Element.
- #method_missing(name, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Methods included from Ident
Constructor Details
#initialize(name, parent:, attributes: {}, contents: [], &block) ⇒ Element
Returns a new instance of Element.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sevgi/graphics/element.rb', line 34 def initialize(name, parent:, attributes: {}, contents: [], &block) @name = name @attributes = Attributes.new(attributes) @children = [] @contents = contents @parent = parent 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
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
32 33 34 |
# File 'lib/sevgi/graphics/element.rb', line 32 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
32 33 34 |
# File 'lib/sevgi/graphics/element.rb', line 32 def children @children end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
32 33 34 |
# File 'lib/sevgi/graphics/element.rb', line 32 def contents @contents end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/sevgi/graphics/element.rb', line 32 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
32 33 34 |
# File 'lib/sevgi/graphics/element.rb', line 32 def parent @parent end |
Class Method Details
.element(name, parent:, &block) ⇒ Object
8 |
# File 'lib/sevgi/graphics/element.rb', line 8 def self.element(name, *, parent:, &block) = new(name, **Dispatch.parse(name, *), parent:, &block) |
.root(&block) ⇒ Object
10 |
# File 'lib/sevgi/graphics/element.rb', line 10 def self.root(*, &block) = element(:svg, *, parent: RootParent, &block) |
.root?(element) ⇒ Boolean
12 |
# File 'lib/sevgi/graphics/element.rb', line 12 def self.root?(element) = element.parent == RootParent |