Class: Dieses::Geometry::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/dieses/geometry/element.rb

Direct Known Subclasses

Line, Rect

Defined Under Namespace

Classes: BoundingBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElement

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

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/dieses/geometry/element.rb', line 8

def attributes
  @attributes
end

#hashObject (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(*tags, **kwargs)
  existing_class = attributes[:class] || Set.new
  attr(**kwargs, class: existing_class.add(tags))
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


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_svgObject



27
28
29
# File 'lib/dieses/geometry/element.rb', line 27

def to_svg
  format to_svgf, attributes: Support.kwargs_to_s(**attributes)
end