Class: Umlify::UmlClass

Inherits:
Object
  • Object
show all
Defined in:
lib/umlify/uml_class.rb

Overview

Represents a parsed uml class

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#associationsObject

Returns the value of attribute associations.



5
6
7
# File 'lib/umlify/uml_class.rb', line 5

def associations
  @associations
end

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/umlify/uml_class.rb', line 5

def children
  @children
end

#methodsObject

Returns the value of attribute methods.



5
6
7
# File 'lib/umlify/uml_class.rb', line 5

def methods
  @methods
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/umlify/uml_class.rb', line 5

def name
  @name
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/umlify/uml_class.rb', line 5

def parent
  @parent
end

#variablesObject

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_sObject



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