Class: Lutaml::Formatter::Base
- Inherits:
-
Object
- Object
- Lutaml::Formatter::Base
- Includes:
- Lml::HasAttributes
- Defined in:
- lib/lutaml/lml/formatter/base.rb
Direct Known Subclasses
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
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #dispatch_format(node) ⇒ Object
- #format(node) ⇒ Object
- #format_attribute(_node) ⇒ Object
- #format_class(_node) ⇒ Object
- #format_document(_node) ⇒ Object
- #format_operation(_node) ⇒ Object
- #format_relationship(_node) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #name ⇒ Object
Methods included from Lml::HasAttributes
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
#type ⇒ Object
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 |
.name ⇒ Object
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
72 |
# File 'lib/lutaml/lml/formatter/base.rb', line 72 def format_attribute(_node) = raise(NotImplementedError) |
#format_class(_node) ⇒ Object
75 |
# File 'lib/lutaml/lml/formatter/base.rb', line 75 def format_class(_node) = raise(NotImplementedError) |
#format_document(_node) ⇒ Object
76 |
# File 'lib/lutaml/lml/formatter/base.rb', line 76 def format_document(_node) = raise(NotImplementedError) |
#format_operation(_node) ⇒ Object
73 |
# File 'lib/lutaml/lml/formatter/base.rb', line 73 def format_operation(_node) = raise(NotImplementedError) |
#format_relationship(_node) ⇒ Object
74 |
# File 'lib/lutaml/lml/formatter/base.rb', line 74 def format_relationship(_node) = raise(NotImplementedError) |
#name ⇒ Object
48 49 50 |
# File 'lib/lutaml/lml/formatter/base.rb', line 48 def name self.class.name end |