Sha256: f87a33c97e57ed663f5379cc9c6b22ab843563cf7c2457f7cd39cad488f5ecb5

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module DrawioDsl
  module Schema
    # Node is a base class for shapes, connections, positioners and layout rules
    #
    class Node
      attr_accessor :id
      attr_accessor :page
      attr_accessor :classification

      def initialize(page, **args)
        @page = page
        @id = args[:id]
        @classification = args[:classification] || :unknown
      end

      def to_h
        {
          id: id,
          classification: classification
        }
      end

      # :nocov:
      # rubocop:disable Metrics/AbcSize
      def debug(format: :detail)
        if format == :detail
          debug_detail(to_h)
        else
          debug_row(classification, id)
        end
      end

      def debug_detail(**key_values)
        key_values.each do |key, value|
          puts "#{key.to_s.ljust(15)}: #{value}"
        end
      end

      # rubocop:disable Metrics/ParameterLists
      def debug_row(classification, id, type = nil, x = nil, y = nil, width = nil, height = nil)
        row = []
        row << classification.to_s.ljust(11)
        row << id.to_s.ljust(6)
        row << (type.nil? ? '' : type).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
      # rubocop:enable Metrics/ParameterLists
      # :nocov:
    end
    # rubocop:enable Metrics/AbcSize
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
drawio_dsl-0.5.6 lib/drawio_dsl/schema/node.rb
drawio_dsl-0.5.5 lib/drawio_dsl/schema/node.rb
drawio_dsl-0.5.4 lib/drawio_dsl/schema/node.rb
drawio_dsl-0.5.3 lib/drawio_dsl/schema/node.rb