class Graphviz::Diagram::ClassDiagram::Entity
A entity class with many attributes and methods definition strings
Attributes
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz
labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
A key ‘field_id` will generated in a auto-increment manner if a relationship (e.g., belongs to) are attached to a specific member field.
‘node_attributes` are Graphviz
attributes for the node represents the entity.
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz
labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
A key ‘field_id` will generated in a auto-increment manner if a relationship (e.g., belongs to) are attached to a specific member field.
‘node_attributes` are Graphviz
attributes for the node represents the entity.
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz
labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
A key ‘field_id` will generated in a auto-increment manner if a relationship (e.g., belongs to) are attached to a specific member field.
‘node_attributes` are Graphviz
attributes for the node represents the entity.
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz
labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
A key ‘field_id` will generated in a auto-increment manner if a relationship (e.g., belongs to) are attached to a specific member field.
‘node_attributes` are Graphviz
attributes for the node represents the entity.
Public Class Methods
# File lib/graphviz/diagram/class_diagram.rb, line 24 def initialize(name, attrs = {}) @name, @attributes, @methods = name, [], [] @node_attributes = { shape: 'record' }.merge(attrs) end
Public Instance Methods
# File lib/graphviz/diagram/class_diagram.rb, line 46 def add_attribute(name, opts = {}) opts[:name] = name opts[:visibility] ||= :public opts.keys.each do |k| known_keys = [:name, :visibility, :type, :field_id] fail "unknown attribute #{k}" unless known_keys.include?(k.to_sym) end @attributes << opts end
# File lib/graphviz/diagram/class_diagram.rb, line 56 def add_method(name, opts = {}) opts[:name] = name opts[:visibility] ||= :public opts.keys.each do |k| known_keys = [:name, :visibility, :arguments, :type, :field_id] fail "unknown attribute #{k}" unless known_keys.include?(k.to_sym) end @methods << opts end
# File lib/graphviz/diagram/class_diagram.rb, line 33 def attribute(name) attributes.each { |m| return m if m[:name] == name } end
# File lib/graphviz/diagram/class_diagram.rb, line 66 def belongs_to(entity, opts = {}) Aggragation.new self, entity, opts end
# File lib/graphviz/diagram/class_diagram.rb, line 70 def embedded_in(entity, opts = {}) Composition.new self, entity, opts end
# File lib/graphviz/diagram/class_diagram.rb, line 74 def extends(entity, opts = {}) Generalization.new self, entity, opts end
# File lib/graphviz/diagram/class_diagram.rb, line 78 def implements(entity, opts = {}) Realization.new self, entity, opts end
rubocop:disable MethodLength
# File lib/graphviz/diagram/class_diagram.rb, line 83 def label return name unless node_attributes[:shape].to_sym == :record rl = RecordLabel.new rl.add_row(name) rl.add_separator attributes.each do |at| str = format '%s%s', visibility_symbol(at), at[:name] str = "#{str} : #{at[:type].capitalize}" if at[:type] rl.add_row str, align: :left, field_id: at[:field_id] end rl.add_separator methods.each do |at| arguments = at[:arguments] ? at[:arguments] : '' str = format '%s%s(%s)', visibility_symbol(at), at[:name], arguments.sub(/\A\(/, '').sub(/\)\Z/, '') str = "#{str} : #{at[:type].capitalize}" if at[:type] rl.add_row str, align: :left, field_id: at[:field_id] end rl.to_s end
# File lib/graphviz/diagram/class_diagram.rb, line 29 def member(name) members.each { |m| return m if m[:name] == name } end
All member fields include both attributes and methods
# File lib/graphviz/diagram/class_diagram.rb, line 42 def members @attributes + @methods end
# File lib/graphviz/diagram/class_diagram.rb, line 37 def method(name) methods.each { |m| return m if m[:name] == name } end
Private Instance Methods
# File lib/graphviz/diagram/class_diagram.rb, line 108 def visibility_symbol(key) case key[:visibility].to_sym when :private then '- ' when :protected then '# ' when :derived then '/ ' when :package then '~ ' else '+ ' end end