Class: Clazz

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, parent) ⇒ Clazz

Returns a new instance of Clazz.



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/xmimodel/clazz.rb', line 30

def initialize(xml, parent)
	@xml = xml
	@package = parent.parent
	
	@id = xml.attribute("xmi.id").to_s
	@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

end

Instance Attribute Details

#attributesArray<Attribute> (readonly)

Returns Class attributes.

Returns:



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

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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

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.



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

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<String> (readonly)

Returns Class associations.

Returns:

  • (Array<String>)

    Class associations.



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

def stereotypes
  @stereotypes
end

#tagged_valuesObject (readonly)

Returns the value of attribute tagged_values.



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

def tagged_values
  @tagged_values
end

#xmlObject (readonly)

Returns the value of attribute xml.



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

def xml
  @xml
end

Instance Method Details

#<=>(obj) ⇒ Object



102
103
104
# File 'lib/xmimodel/clazz.rb', line 102

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

#==(obj) ⇒ Object



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

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

#attribute_by_id(attribute_id) ⇒ Object



72
73
74
75
76
# File 'lib/xmimodel/clazz.rb', line 72

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



78
79
80
81
82
# File 'lib/xmimodel/clazz.rb', line 78

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



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

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

#operation_by_name(operation_name) ⇒ Object



84
85
86
87
88
# File 'lib/xmimodel/clazz.rb', line 84

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



90
91
92
93
94
# File 'lib/xmimodel/clazz.rb', line 90

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



96
97
98
99
100
# File 'lib/xmimodel/clazz.rb', line 96

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



119
120
121
# File 'lib/xmimodel/clazz.rb', line 119

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