Sha256: 50d4927d8bf5a86827a537c2a63fbc0222b0b75b3b437e8f828122437ca2a3eb

Contents?: true

Size: 1.69 KB

Versions: 28

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require "lutaml/formatter"
require "lutaml/uml/has_attributes"

module Lutaml
  module Formatter
    class Base
      class << self
        def inherited(subclass)
          Formatter.all << subclass
        end

        def format(node, attributes = {})
          new(attributes).format(node)
        end

        def name
          to_s.split("::").last.downcase.to_sym
        end
      end

      include ::Lutaml::Uml::HasAttributes

      # rubocop:disable Rails/ActiveRecordAliases
      def initialize(attributes = {})
        update_attributes(attributes)
      end
      # rubocop:enable Rails/ActiveRecordAliases

      def name
        self.class.name
      end

      attr_reader :type

      def type=(value)
        @type = value.to_s.strip.downcase.to_sym
      end

      def format(node)
        case node
        when ::Lutaml::Uml::Node::Field  then format_field(node)
        when ::Lutaml::Uml::Node::Method then format_method(node)
        when ::Lutaml::Uml::Node::Relationship then format_relationship(node)
        when ::Lutaml::Uml::Node::ClassRelationship
          format_class_relationship(node)
        when ::Lutaml::Uml::Node::ClassNode then format_class(node)
        when Lutaml::Uml::Document then format_document(node)
        end
      end

      def format_field(_node); raise NotImplementedError; end

      def format_method(_node); raise NotImplementedError; end

      def format_relationship(_node); raise NotImplementedError; end

      def format_class_relationship(_node); raise NotImplementedError; end

      def format_class(_node); raise NotImplementedError; end

      def format_document(_node); raise NotImplementedError; end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lutaml-0.9.25 lib/lutaml/formatter/base.rb
lutaml-0.9.24 lib/lutaml/formatter/base.rb
lutaml-0.9.23 lib/lutaml/formatter/base.rb
lutaml-0.9.22 lib/lutaml/formatter/base.rb
lutaml-0.9.21 lib/lutaml/formatter/base.rb
lutaml-0.9.20 lib/lutaml/formatter/base.rb
lutaml-0.9.19 lib/lutaml/formatter/base.rb
lutaml-0.9.18 lib/lutaml/formatter/base.rb
lutaml-0.9.17 lib/lutaml/formatter/base.rb
lutaml-0.9.16 lib/lutaml/formatter/base.rb
lutaml-0.9.15 lib/lutaml/formatter/base.rb
lutaml-0.9.14 lib/lutaml/formatter/base.rb
lutaml-0.9.13 lib/lutaml/formatter/base.rb
lutaml-0.9.12 lib/lutaml/formatter/base.rb
lutaml-0.9.11 lib/lutaml/formatter/base.rb
lutaml-0.9.10 lib/lutaml/formatter/base.rb
lutaml-0.9.9 lib/lutaml/formatter/base.rb
lutaml-0.9.8 lib/lutaml/formatter/base.rb
lutaml-0.9.7 lib/lutaml/formatter/base.rb
lutaml-0.9.6 lib/lutaml/formatter/base.rb