Class: Lutaml::Formatter::Base

Inherits:
Object
  • Object
show all
Includes:
Lml::HasAttributes
Defined in:
lib/lutaml/lml/formatter/base.rb

Direct Known Subclasses

Graphviz

Constant Summary collapse

FORMAT_HANDLERS =
{
  Lml::TopElementAttribute => :format_attribute,
  Lml::Operation => :format_operation,
  Lml::Association => :format_relationship,
  Lml::Document => :format_document,
  Lml::DataType => :format_class,
  Lml::UmlClass => :format_class,
  Lml::Enum => :format_class
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lml::HasAttributes

#update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



44
45
46
# File 'lib/lutaml/lml/formatter/base.rb', line 44

def initialize(attributes = {})
  update_attributes(attributes)
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



52
53
54
# File 'lib/lutaml/lml/formatter/base.rb', line 52

def type
  @type
end

Class Method Details

.format(node, attributes = {}) ⇒ Object



33
34
35
# File 'lib/lutaml/lml/formatter/base.rb', line 33

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

.inherited(subclass) ⇒ Object



28
29
30
31
# File 'lib/lutaml/lml/formatter/base.rb', line 28

def inherited(subclass)
  super
  Formatter.all << subclass
end

.nameObject



37
38
39
# File 'lib/lutaml/lml/formatter/base.rb', line 37

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

Instance Method Details

#dispatch_format(node) ⇒ Object



65
66
67
68
69
70
# File 'lib/lutaml/lml/formatter/base.rb', line 65

def dispatch_format(node)
  handler = FORMAT_HANDLERS.find { |type, _| node.is_a?(type) }&.last
  return unless handler

  public_send(handler, node)
end

#format(node) ⇒ Object



58
59
60
61
62
63
# File 'lib/lutaml/lml/formatter/base.rb', line 58

def format(node)
  result = dispatch_format(node)
  return unless result

  result
end

#format_attribute(_node) ⇒ Object

Raises:

  • (NotImplementedError)


72
# File 'lib/lutaml/lml/formatter/base.rb', line 72

def format_attribute(_node) = raise(NotImplementedError)

#format_class(_node) ⇒ Object

Raises:

  • (NotImplementedError)


75
# File 'lib/lutaml/lml/formatter/base.rb', line 75

def format_class(_node) = raise(NotImplementedError)

#format_document(_node) ⇒ Object

Raises:

  • (NotImplementedError)


76
# File 'lib/lutaml/lml/formatter/base.rb', line 76

def format_document(_node) = raise(NotImplementedError)

#format_operation(_node) ⇒ Object

Raises:

  • (NotImplementedError)


73
# File 'lib/lutaml/lml/formatter/base.rb', line 73

def format_operation(_node) = raise(NotImplementedError)

#format_relationship(_node) ⇒ Object

Raises:

  • (NotImplementedError)


74
# File 'lib/lutaml/lml/formatter/base.rb', line 74

def format_relationship(_node) = raise(NotImplementedError)

#nameObject



48
49
50
# File 'lib/lutaml/lml/formatter/base.rb', line 48

def name
  self.class.name
end