Sha256: b43caba49ebc471298d801f727d508ff5ee41ed135080152ca4ab4f02eefd04a

Contents?: true

Size: 1.69 KB

Versions: 16

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
          then 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

16 entries across 16 versions & 1 rubygems

Version Path
lutaml-0.7.5 lib/lutaml/formatter/base.rb
lutaml-0.7.4 lib/lutaml/formatter/base.rb
lutaml-0.7.3 lib/lutaml/formatter/base.rb
lutaml-0.7.2 lib/lutaml/formatter/base.rb
lutaml-0.7.1 lib/lutaml/formatter/base.rb
lutaml-0.7.0 lib/lutaml/formatter/base.rb
lutaml-0.6.1 lib/lutaml/formatter/base.rb
lutaml-0.6.0 lib/lutaml/formatter/base.rb
lutaml-0.5.2 lib/lutaml/formatter/base.rb
lutaml-0.5.1 lib/lutaml/formatter/base.rb
lutaml-0.5.0 lib/lutaml/formatter/base.rb
lutaml-0.4.1 lib/lutaml/formatter/base.rb
lutaml-0.4.1.pre.alpha.2 lib/lutaml/formatter/base.rb
lutaml-0.4.1.pre.alpha.1 lib/lutaml/formatter/base.rb
lutaml-0.4.1.pre.alpha lib/lutaml/formatter/base.rb
lutaml-0.4.0 lib/lutaml/formatter/base.rb