Class: DYI::Element Abstract

Inherits:
Object
  • Object
show all
Extended by:
AttributeCreator
Defined in:
lib/dyi/element.rb

Overview

This class is abstract.

Abstract class that represents a element contained in the image.

Since:

  • 1.0.0

Constant Summary collapse

ID_REGEXP =

Since:

  • 1.0.0

/\A[:A-Z_a-z][\-\.0-9:A-Z_a-z]*\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionString

Returns a description of the element.

Returns:

  • (String)

    a description of the element

Since:

  • 1.1.1



40
41
42
# File 'lib/dyi/element.rb', line 40

def description
  @description
end

#titleString

Returns a title of the element.

Returns:

  • (String)

    a title of the element

Since:

  • 1.1.1



35
36
37
# File 'lib/dyi/element.rb', line 35

def title
  @title
end

Instance Method Details

#canvasCanvas

Returns the canvas where the shape is drawn.

Returns:

  • (Canvas)

    the canvas where the shape is drawn

Since:

  • 1.0.0



70
71
72
73
74
75
76
# File 'lib/dyi/element.rb', line 70

def canvas
  current_node = self
  loop do
    return current_node if current_node.nil? || current_node.root_element?
    current_node = current_node.parent
  end
end

#child_elementsArray<Element>

Returns an array of child elements.

Returns:

  • (Array<Element>)

    an empty array

Since:

  • 1.0.0



80
81
82
# File 'lib/dyi/element.rb', line 80

def child_elements
  []
end

#has_uri_reference?Boolean

Returns whether the element has URI reference.

Returns:

  • (Boolean)

    always false

Since:

  • 1.0.0



92
93
94
# File 'lib/dyi/element.rb', line 92

def has_uri_reference?
  false
end

#idString Also known as: publish_id

Returns id for the element. If the element has no id yet, makes id and returns it.

Returns:

  • (String)

    id for the element

Since:

  • 1.0.0



45
46
47
# File 'lib/dyi/element.rb', line 45

def id
  @id ||= canvas && canvas.publish_shape_id
end

#id=(value) ⇒ String

Sets id for the element.

Parameters:

  • value (String)

    id for the element

Returns:

  • (String)

    id that is given

Raises:

  • (ArgumentError)

    value is empty or illegal format

Since:

  • 1.0.0



61
62
63
64
65
66
# File 'lib/dyi/element.rb', line 61

def id=(value)
  # TODO: veryfy that the id is unique.
  raise ArgumentError, "`#{value}' is empty" if value.to_s.size == 0
  raise ArgumentError, "`#{value}' is a illegal id" if value.to_s !~ ID_REGEXP
  @id = value.to_s
end

#include_external_file?Boolean

Returns whether the element has reference of external file.

Returns:

  • (Boolean)

    always false

Since:

  • 1.0.0



86
87
88
# File 'lib/dyi/element.rb', line 86

def include_external_file?
  false
end

#inner_idString

Returns id of the element. If the element has no id yet, returns nil.

Returns:

  • (String)

    id for the element if it has id, nil if not

Since:

  • 1.0.0



53
54
55
# File 'lib/dyi/element.rb', line 53

def inner_id
  @id
end