Class: ERDEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-erd/erd_entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ruby-erd/erd_entity.rb', line 3

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/ruby-erd/erd_entity.rb', line 3

def node
  @node
end

Instance Method Details

#attributes=(attributes) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/ruby-erd/erd_entity.rb', line 5

def attributes=(attributes)
  attributes_as_string = attributes.collect do |key, value|
    "#{key} :#{value}"
  end.join('\l')

  @node.label = "{#{name}| #{attributes_as_string}}"
end

#background_color=(color) ⇒ Object



13
14
15
16
# File 'lib/ruby-erd/erd_entity.rb', line 13

def background_color=(color)
  @node.color = color
  @node.style = :filled
end

#build(attributes) ⇒ Object



18
19
20
21
22
23
# File 'lib/ruby-erd/erd_entity.rb', line 18

def build(attributes)
  @graph = attributes[:graph]
  @name  = attributes[:name]
  # Returns a GraphViz::Node
  @node = @graph.add_nodes(name, shape: 'record')
end