Sha256: d0f2a144a131c0568626230385ebd938fa2d6bd7e7f3db1f8a90bd582b4e9e09

Contents?: true

Size: 884 Bytes

Versions: 31

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

module DrawioDsl
  module Schema
    class NodeList
      attr_reader :nodes

      def initialize
        @nodes = []
      end

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

      def all
        @nodes
      end

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

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

      def length
        @nodes.length
      end

      def empty?
        @nodes.empty?
      end

      def any?
        @nodes.any?
      end

      def first
        @nodes.first
      end

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

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
drawio_dsl-0.12.4 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.12.3 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.12.2 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.12.1 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.12.0 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.8 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.7 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.6 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.5 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.4 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.3 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.2 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.1 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.11.0 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.10.1 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.10.0 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.9.0 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.8.11 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.8.10 lib/drawio_dsl/schema/node_list.rb
drawio_dsl-0.8.9 lib/drawio_dsl/schema/node_list.rb