Class: DrawioDsl::Schema::Node
- Inherits:
-
Object
- Object
- DrawioDsl::Schema::Node
- Defined in:
- lib/drawio_dsl/schema/node.rb
Overview
Node is a base class for shapes, connections, positioners and layout rules
Instance Attribute Summary collapse
-
#classification ⇒ Object
What is the class of this node? [anchor, layout_rule, shape, line, ].
-
#id ⇒ Object
Unique ID so that nodes can be referenced.
-
#key ⇒ Object
Represents the node type as a string [circle, square, diamond, line].
-
#nodes ⇒ Object
Child nodes.
-
#page ⇒ Object
What drawio page is this node on?.
-
#parent ⇒ Object
What is the parent node?.
Instance Method Summary collapse
- #add_node(node) ⇒ Object
-
#debug(format: :detail) ⇒ Object
:nocov: rubocop:disable Metrics/AbcSize.
- #debug_detail(**key_values) ⇒ Object
-
#debug_row(classification, id, key = nil, x = nil, y = nil, width = nil, height = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#initialize(page, **args) ⇒ Node
constructor
A new instance of Node.
- #root? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(page, **args) ⇒ Node
Returns a new instance of Node.
26 27 28 29 30 31 32 33 |
# File 'lib/drawio_dsl/schema/node.rb', line 26 def initialize(page, **args) @page = page @id = args[:id] @parent = args[:parent] @classification = args[:classification] || :unknown @key = args[:key] || :unknown @nodes = NodeList.new end |
Instance Attribute Details
#classification ⇒ Object
What is the class of this node? [anchor, layout_rule, shape, line, ]
18 19 20 |
# File 'lib/drawio_dsl/schema/node.rb', line 18 def classification @classification end |
#id ⇒ Object
Unique ID so that nodes can be referenced
9 10 11 |
# File 'lib/drawio_dsl/schema/node.rb', line 9 def id @id end |
#key ⇒ Object
Represents the node type as a string [circle, square, diamond, line]
21 22 23 |
# File 'lib/drawio_dsl/schema/node.rb', line 21 def key @key end |
#nodes ⇒ Object
Child nodes
24 25 26 |
# File 'lib/drawio_dsl/schema/node.rb', line 24 def nodes @nodes end |
#page ⇒ Object
What drawio page is this node on?
12 13 14 |
# File 'lib/drawio_dsl/schema/node.rb', line 12 def page @page end |
#parent ⇒ Object
What is the parent node?
15 16 17 |
# File 'lib/drawio_dsl/schema/node.rb', line 15 def parent @parent end |
Instance Method Details
#add_node(node) ⇒ Object
50 51 52 53 |
# File 'lib/drawio_dsl/schema/node.rb', line 50 def add_node(node) @nodes.add(self, node) node end |
#debug(format: :detail) ⇒ Object
:nocov: rubocop:disable Metrics/AbcSize
57 58 59 60 61 62 63 |
# File 'lib/drawio_dsl/schema/node.rb', line 57 def debug(format: :detail) if format == :detail debug_detail(to_h) else debug_row(classification, id) end end |
#debug_detail(**key_values) ⇒ Object
65 66 67 68 69 |
# File 'lib/drawio_dsl/schema/node.rb', line 65 def debug_detail(**key_values) key_values.each do |key, value| puts "#{key.to_s.ljust(15)}: #{value}" end end |
#debug_row(classification, id, key = nil, x = nil, y = nil, width = nil, height = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/drawio_dsl/schema/node.rb', line 72 def debug_row(classification, id, key = nil, x = nil, y = nil, width = nil, height = nil) row = [] row << classification.to_s.ljust(11) row << id.to_s.ljust(6) row << (key.nil? ? '' : key).to_s.ljust(15) row << (x.nil? ? '' : x).to_s.rjust(5) row << (y.nil? ? '' : y).to_s.rjust(5) row << (width.nil? ? '' : width).to_s.rjust(5) row << (height.nil? ? '' : height).to_s.rjust(5) puts row.join(' | ') end |
#root? ⇒ Boolean
46 47 48 |
# File 'lib/drawio_dsl/schema/node.rb', line 46 def root? parent.nil? || parent.is_a?(DrawioDsl::Schema::Page) end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/drawio_dsl/schema/node.rb', line 35 def to_h result = { id: id, parent_id: parent&.id, classification: classification, key: key } result[:nodes] = nodes.to_h if nodes.any? result end |