Class: Sevgi::Graphics::Element
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Element
- Extended by:
- Ident
- Defined in:
- lib/sevgi/graphics/element.rb
Overview
SVG element node used by the graphics DSL.
Direct Known Subclasses
Defined Under Namespace
Modules: Ident
Constant Summary collapse
- RootParent =
Sentinel parent used by root SVG elements.
Object.new.tap { def it.inspect = "RootParent" }.freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Sevgi::Graphics::Attributes
readonly
Attribute store.
-
#children ⇒ Array<Sevgi::Graphics::Element>
readonly
Child elements.
-
#contents ⇒ Array<Sevgi::Graphics::Content>
readonly
Element content objects.
-
#name ⇒ Symbol
readonly
SVG element name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.element(name, parent:, &block) ⇒ Sevgi::Graphics::Element
Builds an element node.
-
.root(&block) ⇒ Sevgi::Graphics::Element
Builds an SVG root element.
-
.root?(element) ⇒ Boolean
Reports whether an element is the root element.
Instance Method Summary collapse
-
#initialize(name, parent:, attributes: {}, contents: [], &block) ⇒ void
constructor
Creates an element.
-
#method_missing(name, &block) ⇒ Sevgi::Graphics::Element
Dispatches SVG element DSL calls and caches valid element methods.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Reports whether a missing method can dispatch to an SVG element.
Methods included from Ident
Constructor Details
#initialize(name, parent:, attributes: {}, contents: [], &block) ⇒ void
Creates an element.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sevgi/graphics/element.rb', line 73 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
#method_missing(name, &block) ⇒ Sevgi::Graphics::Element
Dispatches SVG element DSL calls and caches valid element methods.
90 91 92 |
# File 'lib/sevgi/graphics/element.rb', line 90 def method_missing(name, *, &block) Element.valid?(tag = Element.id(name)) ? Dispatch.(self, name, tag, *, &block) : super end |
Instance Attribute Details
#attributes ⇒ Sevgi::Graphics::Attributes
Returns attribute store.
65 |
# File 'lib/sevgi/graphics/element.rb', line 65 attr_reader :name, :attributes, :children, :contents, :parent |
#children ⇒ Array<Sevgi::Graphics::Element>
Returns child elements.
65 |
# File 'lib/sevgi/graphics/element.rb', line 65 attr_reader :name, :attributes, :children, :contents, :parent |
#contents ⇒ Array<Sevgi::Graphics::Content> (readonly)
Returns element content objects.
65 |
# File 'lib/sevgi/graphics/element.rb', line 65 attr_reader :name, :attributes, :children, :contents, :parent |
#name ⇒ Symbol (readonly)
Returns SVG element name.
65 66 67 |
# File 'lib/sevgi/graphics/element.rb', line 65 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
65 |
# File 'lib/sevgi/graphics/element.rb', line 65 attr_reader :name, :attributes, :children, :contents, :parent |
Class Method Details
.element(name, parent:, &block) ⇒ Sevgi::Graphics::Element
Builds an element node.
12 |
# File 'lib/sevgi/graphics/element.rb', line 12 def self.element(name, *, parent:, &block) = new(name, **Dispatch.parse(name, *), parent:, &block) |
.root(&block) ⇒ Sevgi::Graphics::Element
Builds an SVG root element.
17 |
# File 'lib/sevgi/graphics/element.rb', line 17 def self.root(*, &block) = element(:svg, *, parent: RootParent, &block) |
.root?(element) ⇒ Boolean
Reports whether an element is the root element.
22 |
# File 'lib/sevgi/graphics/element.rb', line 22 def self.root?(element) = element.parent == RootParent |