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
- .format(node, attributes = {}) ⇒ Object
-
.formatter_name ⇒ Object
Registry key for Formatter.find_by_name.
- .inherited(subclass) ⇒ Object
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.
47 48 49 |
# File 'lib/lutaml/lml/formatter/base.rb', line 47 def initialize(attributes = {}) update_attributes(attributes) end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
55 56 57 |
# File 'lib/lutaml/lml/formatter/base.rb', line 55 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 |
.formatter_name ⇒ Object
Registry key for Formatter.find_by_name. Deliberately not
name — shadowing Class#name breaks Ruby internals and any
library that legitimately calls .name on these classes.
40 41 42 |
# File 'lib/lutaml/lml/formatter/base.rb', line 40 def formatter_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 raise Lml::Error, "no format handler for #{node.class}" unless handler public_send(handler, node) end |
#format(node) ⇒ Object
61 62 63 |
# File 'lib/lutaml/lml/formatter/base.rb', line 61 def format(node) dispatch_format(node) 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
51 52 53 |
# File 'lib/lutaml/lml/formatter/base.rb', line 51 def name self.class.formatter_name end |