Sha256: 56ddeec4991e8f453cc9e8c3411eec9b6905a7017437ed40cda4c137a213487d

Contents?: true

Size: 1.76 KB

Versions: 48

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

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

module Lutaml
  module Uml
    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 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 Node::Field  then format_field(node)
          when Node::Method then format_method(node)
          when Node::Relationship then format_relationship(node)
          when Node::ClassRelationship then format_class_relationship(node)
          when 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
end

Version data entries

48 entries across 48 versions & 2 rubygems

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