Class: DrawioDsl::Schema::NodeList

Inherits:
Object
  • Object
show all
Defined in:
lib/drawio_dsl/schema/node_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ NodeList



8
9
10
# File 'lib/drawio_dsl/schema/node_list.rb', line 8

def initialize
  @nodes = []
end

Instance Attribute Details

#nodes ⇒ Object (readonly)

Returns the value of attribute nodes.



6
7
8
# File 'lib/drawio_dsl/schema/node_list.rb', line 6

def nodes
  @nodes
end

Instance Method Details

#add(parent, node) ⇒ Object



12
13
14
15
# File 'lib/drawio_dsl/schema/node_list.rb', line 12

def add(parent, node)
  node.parent = parent
  @nodes << node
end

#all ⇒ Object



17
18
19
# File 'lib/drawio_dsl/schema/node_list.rb', line 17

def all
  @nodes
end

#any? ⇒ Boolean



37
38
39
# File 'lib/drawio_dsl/schema/node_list.rb', line 37

def any?
  @nodes.any?
end

#as_xml(xml) ⇒ Object



45
46
47
48
49
# File 'lib/drawio_dsl/schema/node_list.rb', line 45

def as_xml(xml)
  nodes.each do |node|
    node.as_xml(xml) if node.respond_to?(:as_xml)
  end
end

#empty? ⇒ Boolean



33
34
35
# File 'lib/drawio_dsl/schema/node_list.rb', line 33

def empty?
  @nodes.empty?
end

#first ⇒ Object



41
42
43
# File 'lib/drawio_dsl/schema/node_list.rb', line 41

def first
  @nodes.first
end

#layouts ⇒ Object



25
26
27
# File 'lib/drawio_dsl/schema/node_list.rb', line 25

def layouts
  @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Layout) }
end

#length ⇒ Object



29
30
31
# File 'lib/drawio_dsl/schema/node_list.rb', line 29

def length
  @nodes.length
end

#shapes ⇒ Object



21
22
23
# File 'lib/drawio_dsl/schema/node_list.rb', line 21

def shapes
  @nodes.select { |node| node.is_a?(DrawioDsl::Schema::Shape) }
end

#to_h ⇒ Object



51
52
53
# File 'lib/drawio_dsl/schema/node_list.rb', line 51

def to_h
  @nodes.map(&:to_h)
end