Class: Clazz

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

Returns a new instance of Clazz.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/xmimodel/clazz.rb', line 33

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

	@package = parent_tag.parent_tag
			
	@name = xml.attribute("name").to_s.strip
	
	@attributes = Array.new
	XmiHelper.attributes(xml).each do |uml_attribute|
		attribute = Attribute.new(uml_attribute, self)
		@attributes << attribute			
	end

	@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

	@operations = Array.new
	XmiHelper.operations(xml).each do |uml_operation|
		tagged_value = Operation.new(uml_operation, self)
		@operations << tagged_value
	end

	# Será povoado quando tratar dos objetos do tipo Genezalization
	@children = Array.new

	@associations = Array.new

end

Instance Attribute Details

#associationsArray<AssociationEnd> (readonly)

Returns Class associations end.

Returns:



31
32
33
# File 'lib/xmimodel/clazz.rb', line 31

def associations
  @associations
end

#attributesArray<Attribute> (readonly)

Returns Class attributes.

Returns:



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

def attributes
  @attributes
end

#childrenObject

Returns the value of attribute children.



27
28
29
# File 'lib/xmimodel/clazz.rb', line 27

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations.



25
26
27
# File 'lib/xmimodel/clazz.rb', line 25

def operations
  @operations
end

#packageString (readonly)

Returns Full Package name of class.

Returns:

  • (String)

    Full Package name of class.



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

def package
  @package
end

#parentObject

Returns the value of attribute parent.



28
29
30
# File 'lib/xmimodel/clazz.rb', line 28

def parent
  @parent
end

#stereotypesArray<Stereotype> (readonly)

Returns Class stereotypes.

Returns:



20
21
22
# File 'lib/xmimodel/clazz.rb', line 20

def stereotypes
  @stereotypes
end

#tagged_valuesArray<TaggedValue> (readonly)

Returns Class tagged values.

Returns:



23
24
25
# File 'lib/xmimodel/clazz.rb', line 23

def tagged_values
  @tagged_values
end

Instance Method Details

#<=>(obj) ⇒ Object



150
151
152
# File 'lib/xmimodel/clazz.rb', line 150

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

#==(obj) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/xmimodel/clazz.rb', line 154

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

#add_xml_attribute(xml_attribute) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/xmimodel/clazz.rb', line 77

def add_xml_attribute(xml_attribute)
	parent = self.xml.at_xpath('./UML:Classifier.feature')
	if parent.nil?
		parent = Nokogiri::XML::Node.new('Classifier.feature', self.xml.document)
		self.xml << parent
	end		
	parent.inner_html = parent.inner_html + xml_attribute

	@attributes << Attribute.new(uml_attribute, self)		
end

#add_xml_stereotype(xml) ⇒ Object

Parameters:

  • xml (Nokogiri::XML::Element, #read)


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/xmimodel/clazz.rb', line 90

def add_xml_stereotype(xml)		
	parent = self.xml.at_xpath('./UML:ModelElement.stereotype')
	if parent.nil?
		parent = Nokogiri::XML::Node.new('ModelElement.stereotype', self.xml.document)
		self.xml << parent
	end		
	parent.inner_html = parent.inner_html + xml.to_xml

	stereotype = Stereotype.new(xml, self)
	@stereotypes << stereotype
	return stereotype
end

#association_end_by_name_and_participant(associations_end_name, participant) ⇒ AssociationEnd

Parameters:

  • associations_end_name (String, #read)
  • participant (Clazz, #read)

Returns:



107
108
109
110
111
# File 'lib/xmimodel/clazz.rb', line 107

def association_end_by_name_and_participant(associations_end_name, participant)
	obj = @associations.select{|obj| obj.name == associations_end_name && obj.participant == participant}
	return obj[0] if !obj.nil? && obj.size > 0
	nil
end

#associations_end_by_participant(participant) ⇒ Array<AssociationEnd>

Parameters:

  • participant (Clazz, #read)

Returns:



116
117
118
# File 'lib/xmimodel/clazz.rb', line 116

def associations_end_by_participant(participant)
	obj = @associations.select{|obj| obj.participant == participant}
end

#attribute_by_id(attribute_id) ⇒ Object



120
121
122
123
124
# File 'lib/xmimodel/clazz.rb', line 120

def attribute_by_id(attribute_id)
	attribute = @attributes.select{|obj| obj.id == attribute_id}
	return attribute[0] if !attribute.nil? && attribute.size > 0
	nil
end

#attribute_by_name(attribute_name) ⇒ Object



126
127
128
129
130
# File 'lib/xmimodel/clazz.rb', line 126

def attribute_by_name(attribute_name)
	attribute = @attributes.select{|obj| obj.name == attribute_name}
	return attribute[0] if !attribute.nil? && attribute.size > 0
	nil
end

#full_nameObject



163
164
165
# File 'lib/xmimodel/clazz.rb', line 163

def full_name
	"#{package.full_name}.#{name}"
end

#operation_by_name(operation_name) ⇒ Object



132
133
134
135
136
# File 'lib/xmimodel/clazz.rb', line 132

def operation_by_name(operation_name)
	operation = @operations.select{|obj| obj.name == operation_name}
	return operation[0] if !operation.nil? && operation.size > 0
	nil
end

#stereotype_by_name(name) ⇒ Object



138
139
140
141
142
# File 'lib/xmimodel/clazz.rb', line 138

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

#tagged_value_by_name(tagged_value_name) ⇒ Object



144
145
146
147
148
# File 'lib/xmimodel/clazz.rb', line 144

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

#to_sObject



167
168
169
# File 'lib/xmimodel/clazz.rb', line 167

def to_s
	"Clazz[#{full_name}]"
end