Class: Graphviz::Diagram::ClassDiagram::Entity
- Inherits:
-
Object
- Object
- Graphviz::Diagram::ClassDiagram::Entity
- Defined in:
- lib/graphviz/diagram/class_diagram.rb
Overview
A entity class with many attributes and methods definition strings
Instance Attribute Summary collapse
-
#attributes ⇒ Object
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
-
#methods ⇒ Object
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
-
#name ⇒ Object
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
-
#node_attributes ⇒ Object
The ‘attributes` and `methods` are lists of Hashes contain information necessary to produce Graphviz labels, such as `name`, `visibility`, `arguments` (for methods) and `type`.
Instance Method Summary collapse
- #add_attribute(name, opts = {}) ⇒ Object
- #add_method(name, opts = {}) ⇒ Object
- #attribute(name) ⇒ Object
- #belongs_to(entity, opts = {}) ⇒ Object
- #embedded_in(entity, opts = {}) ⇒ Object
- #extends(entity, opts = {}) ⇒ Object
- #implements(entity, opts = {}) ⇒ Object
-
#initialize(name, attrs = {}) ⇒ Entity
constructor
A new instance of Entity.
-
#label ⇒ Object
rubocop:disable MethodLength.
- #member(name) ⇒ Object
-
#members ⇒ Object
All member fields include both attributes and methods.
- #method(name) ⇒ Object
Constructor Details
#initialize(name, attrs = {}) ⇒ Entity
Returns a new instance of Entity.
24 25 26 27 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 24 def initialize(name, attrs = {}) @name, @attributes, @methods = name, [], [] @node_attributes = { shape: 'record' }.merge(attrs) end |
Instance Attribute Details
#attributes ⇒ Object
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.
23 24 25 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 23 def attributes @attributes end |
#methods ⇒ Object
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.
23 24 25 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 23 def methods @methods end |
#name ⇒ Object
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.
23 24 25 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 23 def name @name end |
#node_attributes ⇒ Object
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.
23 24 25 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 23 def node_attributes @node_attributes end |
Instance Method Details
#add_attribute(name, opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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 |
#add_method(name, opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# 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 |
#attribute(name) ⇒ Object
33 34 35 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 33 def attribute(name) attributes.each { |m| return m if m[:name] == name } end |
#belongs_to(entity, opts = {}) ⇒ Object
66 67 68 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 66 def belongs_to(entity, opts = {}) Aggragation.new self, entity, opts end |
#embedded_in(entity, opts = {}) ⇒ Object
70 71 72 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 70 def (entity, opts = {}) Composition.new self, entity, opts end |
#extends(entity, opts = {}) ⇒ Object
74 75 76 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 74 def extends(entity, opts = {}) Generalization.new self, entity, opts end |
#implements(entity, opts = {}) ⇒ Object
78 79 80 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 78 def implements(entity, opts = {}) Realization.new self, entity, opts end |
#label ⇒ Object
rubocop:disable MethodLength
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 |
#member(name) ⇒ Object
29 30 31 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 29 def member(name) members.each { |m| return m if m[:name] == name } end |
#members ⇒ Object
All member fields include both attributes and methods
42 43 44 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 42 def members @attributes + @methods end |
#method(name) ⇒ Object
37 38 39 |
# File 'lib/graphviz/diagram/class_diagram.rb', line 37 def method(name) methods.each { |m| return m if m[:name] == name } end |