Class: Stereotype

Inherits:
Tag
  • Object
show all
Defined in:
lib/xmimodel/stereotype.rb

Instance Attribute Summary collapse

Attributes inherited from Tag

#id, #parent_tag, #xml

Instance Method Summary collapse

Methods inherited from Tag

#xml_root

Constructor Details

#initialize(xml, parent_tag) ⇒ Stereotype

Returns a new instance of Stereotype.



9
10
11
12
13
14
15
# File 'lib/xmimodel/stereotype.rb', line 9

def initialize(xml, parent_tag)
  super(xml, parent_tag)

  @name = xml.attribute("name").to_s
  @href = xml.attribute("href").to_s
  @idref = xml.attribute("xmi.idref").to_s
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



7
8
9
# File 'lib/xmimodel/stereotype.rb', line 7

def href
  @href
end

Instance Method Details

#<=>(obj) ⇒ Object



17
18
19
# File 'lib/xmimodel/stereotype.rb', line 17

def <=>(obj)
    name <=> obj.name
end

#==(obj) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/xmimodel/stereotype.rb', line 21

def ==(obj)
  return false if obj.nil?
  if String == obj.class
    name == obj
  else
      name == obj.name
    end
end

#nameObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/xmimodel/stereotype.rb', line 30

def name
  return @name unless (@name.nil? or @name.empty?)

  @name = XmiHelper.extension_referent_path_value(xml)
  
  if @name.empty?    
    # Se 'xmi.idref' não for null, o documento irá apontar para o id de outra tag 
    # UML:Stereotype (que estará dentro de UML:Namespace.ownedElement e não UML:ModelElement.stereotype)
    id = @idref.empty? ? @href : @idref
    xml = XmiHelper.stereotype_by_id(@xml, id)
    if !xml.nil?
      @id = xml.attribute("xmi.id").to_s
      @name = xml.attribute("name").to_s
      @isSpecification = xml.attribute("isSpecification").to_s
      @isRoot = xml.attribute("isRoot").to_s
      @isLeaf = xml.attribute("isLeaf").to_s
      @isAbstract = xml.attribute("isAbstract").to_s     
    end 
  end
    
  if @name.empty?
    App.logger.warn "Stereotype not found. Id: #{@id}"
    @name = @href
  end  

  @name
end

#to_sObject



58
59
60
# File 'lib/xmimodel/stereotype.rb', line 58

def to_s
  "Stereotype[#{name}]"
end