Class: Ea::Sources::Xmi::AnnotationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/sources/xmi/annotation_builder.rb

Overview

Builds Ea::Model::Annotation instances from XMI owned_comment elements. Each non-empty comment body becomes one Annotation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_id) ⇒ AnnotationBuilder

Returns a new instance of AnnotationBuilder.



11
12
13
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 11

def initialize(owner_id)
  @owner_id = owner_id
end

Instance Attribute Details

#owner_idObject (readonly)

Returns the value of attribute owner_id.



9
10
11
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 9

def owner_id
  @owner_id
end

Class Method Details

.comments_on(element) ⇒ Object



29
30
31
32
33
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 29

def self.comments_on(element)
  return [] unless element.is_a?(::Xmi::Uml::PackagedElement)

  element.owned_comment
end

.from_comments(comments, owner_id, kind: "documentation") ⇒ Object



25
26
27
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 25

def self.from_comments(comments, owner_id, kind: "documentation")
  Array(comments).map { |c| new(owner_id).build(kind, c.body) }
end

.from_element(element, owner_id, kind: "documentation") ⇒ Object

Extract comments from a source element. Only PackagedElement- derived types (Class, Package, Association, etc.) carry owned_comment in the XMI schema; attribute/operation/literal do not. We dispatch on type rather than poking at the method, so unknown element types just yield no annotations.



20
21
22
23
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 20

def self.from_element(element, owner_id, kind: "documentation")
  comments = comments_on(element)
  from_comments(comments, owner_id, kind: kind)
end

Instance Method Details

#build(kind, body, author: nil, modified_date: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ea/sources/xmi/annotation_builder.rb', line 35

def build(kind, body, author: nil, modified_date: nil)
  return nil if body.nil? || body.empty?

  Ea::Model::Annotation.new(
    id: IdNormalizer.synthetic_id(owner_id, kind),
    kind: kind,
    body: body,
    author: author,
    modified_date: modified_date
  )
end