Class: Dieses::Geometry::Element
- Inherits:
-
Object
- Object
- Dieses::Geometry::Element
- Defined in:
- lib/dieses/geometry/element.rb
Defined Under Namespace
Classes: BoundingBox
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #attr(**kwargs) ⇒ Object
- #classify(*tags, **kwargs) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize ⇒ Element
constructor
A new instance of Element.
- #to_svg ⇒ Object
Constructor Details
#initialize ⇒ Element
Returns a new instance of Element.
10 11 12 13 14 |
# File 'lib/dieses/geometry/element.rb', line 10 def initialize @attributes = {} @hash = self.class.hash ^ to_h.hash freeze end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/dieses/geometry/element.rb', line 8 def attributes @attributes end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
8 9 10 |
# File 'lib/dieses/geometry/element.rb', line 8 def hash @hash end |
Instance Method Details
#attr(**kwargs) ⇒ Object
16 17 18 19 20 |
# File 'lib/dieses/geometry/element.rb', line 16 def attr(**kwargs) tap do kwargs.each { |key, value| attributes[key.to_sym] = value } end end |
#classify(*tags, **kwargs) ⇒ Object
22 23 24 25 |
# File 'lib/dieses/geometry/element.rb', line 22 def classify(*, **kwargs) existing_class = attributes[:class] || Set.new attr(**kwargs, class: existing_class.add()) end |
#eql?(other) ⇒ Boolean Also known as: ==
31 32 33 34 35 |
# File 'lib/dieses/geometry/element.rb', line 31 def eql?(other) return false unless other.is_a? self.class to_h == other.to_h end |
#to_svg ⇒ Object
27 28 29 |
# File 'lib/dieses/geometry/element.rb', line 27 def to_svg format to_svgf, attributes: Support.kwargs_to_s(**attributes) end |