Class: Association

Inherits:
Tag
  • Object
show all
Defined in:
lib/xmimodel/association.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) ⇒ Association

Returns a new instance of Association.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xmimodel/association.rb', line 19

def initialize(xml, parent)
	super(xml, parent)

	@name = xml.attribute("name").to_s.strip

	association_end = xml.xpath('./UML:Association.connection/UML:AssociationEnd')

	@end_a = AssociationEnd.new(association_end, 0, self)
	@end_b = AssociationEnd.new(association_end, 1, self)

	@stereotypes = Array.new
	stereotype_id = @xml.attribute("stereotype").to_s
	if !stereotype_id.empty?
		stereotype = XmiHelper.stereotype_by_id(@xml, stereotype_id)
		stereotype = Stereotype.new(stereotype, self)
		@stereotypes << stereotype			
	end
	XmiHelper.stereotypes(@xml).each do |uml_stereotype|
		stereotype = Stereotype.new(uml_stereotype, self)
		@stereotypes << stereotype
	end	

	@tagged_values = Array.new
	XmiHelper.tagged_values(@xml).each do |uml_tagged_value|
		tagged_value = TaggedValue.new(uml_tagged_value, self)
		@tagged_values << tagged_value
	end		
end

Instance Attribute Details

#end_aObject (readonly)

Returns the value of attribute end_a


10
11
12
# File 'lib/xmimodel/association.rb', line 10

def end_a
  @end_a
end

#end_bObject (readonly)

Returns the value of attribute end_b


11
12
13
# File 'lib/xmimodel/association.rb', line 11

def end_b
  @end_b
end

#nameObject (readonly)

Returns the value of attribute name


8
9
10
# File 'lib/xmimodel/association.rb', line 8

def name
  @name
end

#stereotypesArray<Stereotype> (readonly)

Returns Association end stereotypes.

Returns:

  • (Array<Stereotype>)

    Association end stereotypes.


14
15
16
# File 'lib/xmimodel/association.rb', line 14

def stereotypes
  @stereotypes
end

#tagged_valuesArray<TaggedValue> (readonly)

Returns Association end tagged values.

Returns:

  • (Array<TaggedValue>)

    Association end tagged values.


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

def tagged_values
  @tagged_values
end

Instance Method Details

#full_nameString

Returns:

  • (String)

61
62
63
64
65
66
67
# File 'lib/xmimodel/association.rb', line 61

def full_name
	if @name.nil? or @name.empty?
		"#{@end_a.name}[#{@end_a.participant.full_name}] - #{@end_b.name}[#{@end_b.participant.full_name}]"
	else
		"#{@name}(#{@end_a.name}[#{@end_a.participant.full_name}] - #{@end_b.name}[#{@end_b.participant.full_name}])"
	end
end

#stereotype_by_name(name) ⇒ Object


48
49
50
51
52
# File 'lib/xmimodel/association.rb', line 48

def stereotype_by_name(name)
	stereotype = @stereotypes.select{|s| s.name == name}
	return stereotype[0] if !stereotype.nil? && stereotype.size > 0
	nil		
end

#tagged_value_by_name(tagged_value_name) ⇒ Object


54
55
56
57
58
# File 'lib/xmimodel/association.rb', line 54

def tagged_value_by_name(tagged_value_name)
	tagged_value = @tagged_values.select{|t| t.name == tagged_value_name}
	return tagged_value[0] if !tagged_value.nil? && tagged_value.size > 0
	nil			
end

#to_sObject


69
70
71
72
73
74
75
# File 'lib/xmimodel/association.rb', line 69

def to_s
	if @name.nil? or @name.empty?
		"Association[#{@end_a.participant.full_name} - #{@end_b.participant.full_name}]"
	else
		"Association[#{@end_a.participant.full_name} - #{@end_b.participant.full_name} (#{@name})]"
	end
end