Class: YUML::Class

Inherits:
Object
  • Object
show all
Defined in:
lib/yuml/class.rb

Overview

Represents a yUML Class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClass

Returns a new instance of Class.



6
7
8
9
10
# File 'lib/yuml/class.rb', line 6

def initialize
  @methods = []
  @variables = []
  @relationships = []
end

Instance Attribute Details

#name(name = nil) ⇒ Object



12
13
14
15
# File 'lib/yuml/class.rb', line 12

def name(name = nil)
  @name = name if name
  @name
end

Instance Method Details

#associated_with(dest, options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/yuml/class.rb', line 41

def associated_with(dest, options = {})
  options[:type] = :directed_assoication unless i(
    association directed_assoication two_way_association dependency
  ).include?(options[:type])
  relationship = YUML::Relationship.send(options[:type], options[:cardinality])
  @relationships << "[#{name}]#{relationship}[#{dest.name}]"
end

#attach_note(content, options = {}) ⇒ Object



49
50
51
# File 'lib/yuml/class.rb', line 49

def attach_note(content, options = {})
  @relationships << "[#{name}]-#{YUML::Note.create(content, options)}"
end

#has_a(dest, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/yuml/class.rb', line 29

def has_a(dest, options = {})
  options[:type] = :aggregation unless i(composition aggregation).include?(options[:type])
  relationship = YUML::Relationship.send(options[:type], options[:cardinality])
  @relationships << "[#{name}]#{relationship}[#{dest.name}]"
end

#is_a(dest, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/yuml/class.rb', line 35

def is_a(dest, options = {})
  options[:type] = :inheritance unless i(inheritance interface).include?(options[:type])
  relationship = YUML::Relationship.send(options[:type])
  @relationships << "[#{dest.name}]#{relationship}[#{name}]"
end

#methods(*args) ⇒ Object



23
24
25
26
27
# File 'lib/yuml/class.rb', line 23

def methods(*args)
  args.flatten!
  return attributes(@methods) if args.empty?
  @methods << normalize(args)
end

#relationshipsObject



57
58
59
# File 'lib/yuml/class.rb', line 57

def relationships
  "#{@relationships.join(',')}" unless @relationships.empty?
end

#to_sObject



53
54
55
# File 'lib/yuml/class.rb', line 53

def to_s
  "[#{name}#{variables}#{methods}]"
end

#variables(*args) ⇒ Object



17
18
19
20
21
# File 'lib/yuml/class.rb', line 17

def variables(*args)
  args.flatten!
  return attributes(@variables) if args.empty?
  @variables << normalize(args)
end