Class: Umlify::UmlClass
- Inherits:
-
Object
- Object
- Umlify::UmlClass
- Defined in:
- lib/umlify/uml_class.rb
Overview
Represents a parsed uml class
Instance Attribute Summary collapse
-
#associations ⇒ Object
Returns the value of attribute associations.
-
#children ⇒ Object
Returns the value of attribute children.
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
-
#chomp!(classes) ⇒ Object
Deletes variables from the @variables array if they appear in an association.
-
#infer_types!(classes) ⇒ Object
Tries to create an association with the attributes in @variables.
-
#initialize(name) ⇒ UmlClass
constructor
A new instance of UmlClass.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ UmlClass
Returns a new instance of UmlClass.
7 8 9 10 11 12 |
# File 'lib/umlify/uml_class.rb', line 7 def initialize name @name = name @variables = [] @methods = [] @associations = {} end |
Instance Attribute Details
#associations ⇒ Object
Returns the value of attribute associations.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def associations @associations end |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def children @children end |
#methods ⇒ Object
Returns the value of attribute methods.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def methods @methods end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def parent @parent end |
#variables ⇒ Object
Returns the value of attribute variables.
5 6 7 |
# File 'lib/umlify/uml_class.rb', line 5 def variables @variables end |
Instance Method Details
#chomp!(classes) ⇒ Object
Deletes variables from the @variables array if they appear in an association. Sets the @children variable
17 18 19 20 21 22 23 24 25 |
# File 'lib/umlify/uml_class.rb', line 17 def chomp! classes @variables = @variables - @associations.keys unless @associations.nil? @children = classes.select do |c| if c.parent == @name c.parent = nil true end end end |
#infer_types!(classes) ⇒ Object
Tries to create an association with the attributes in @variables.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/umlify/uml_class.rb', line 28 def infer_types! classes class_names = classes.collect {|c| c.name} @variables.each do |attribute| if class_names.include? attribute.classify # A type has match with the attribute's name @associations[attribute] = attribute.classify # If it's a plural, adds a cardinality if attribute == attribute.pluralize @associations[attribute+'-n'] = '*' end end end chomp! classes end |
#to_s ⇒ Object
45 46 47 48 49 |
# File 'lib/umlify/uml_class.rb', line 45 def to_s '['+@name+'|'+ @variables.collect{|var| var}.join(";")+'|'+ @methods.collect{|met| met}.join(";")+']' end |