Class: DYI::Element Abstract
- Inherits:
-
Object
- Object
- DYI::Element
- Extended by:
- AttributeCreator
- Defined in:
- lib/dyi/element.rb
Overview
Abstract class that represents a element contained in the image.
Direct Known Subclasses
Constant Summary collapse
- ID_REGEXP =
/\A[:A-Z_a-z][\-\.0-9:A-Z_a-z]*\z/
Instance Attribute Summary collapse
-
#description ⇒ String
Returns a description of the element.
-
#title ⇒ String
Returns a title of the element.
Instance Method Summary collapse
-
#canvas ⇒ Canvas
Returns the canvas where the shape is drawn.
-
#child_elements ⇒ Array<Element>
Returns an array of child elements.
-
#has_uri_reference? ⇒ Boolean
Returns whether the element has URI reference.
-
#id ⇒ String
(also: #publish_id)
Returns id for the element.
-
#id=(value) ⇒ String
Sets id for the element.
-
#include_external_file? ⇒ Boolean
Returns whether the element has reference of external file.
-
#inner_id ⇒ String
Returns id of the element.
Instance Attribute Details
#description ⇒ String
Returns a description of the element.
40 41 42 |
# File 'lib/dyi/element.rb', line 40 def description @description end |
#title ⇒ String
Returns a title of the element.
35 36 37 |
# File 'lib/dyi/element.rb', line 35 def title @title end |
Instance Method Details
#canvas ⇒ Canvas
Returns the canvas where the shape is drawn.
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_elements ⇒ Array<Element>
Returns an array of child elements.
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.
92 93 94 |
# File 'lib/dyi/element.rb', line 92 def has_uri_reference? false end |
#id ⇒ String Also known as: publish_id
Returns id for the element. If the element has no id yet, makes id and returns it.
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.
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.
86 87 88 |
# File 'lib/dyi/element.rb', line 86 def include_external_file? false end |
#inner_id ⇒ String
Returns id of the element. If the element has no id yet, returns nil.
53 54 55 |
# File 'lib/dyi/element.rb', line 53 def inner_id @id end |