Class: Pgerd::Erd::TableNode

Inherits:
Object
  • Object
show all
Defined in:
lib/pgerd/erd/table_node.rb

Constant Summary collapse

TABLE_TEMPLATE =
<<-END_HTML
<table border="1" align="center" cellborder="0" cellpadding="2" cellspacing="2">
  <tr><td bgcolor="#f8f8f8" align="center" cellpadding="8"><font point-size="11"><%= name %></font></td></tr>
  <% grouped_columns.each_with_index do |group, index| %>
    <% if index > 0 %>
      <tr><td height='3'></td></tr>
    <% end %>
    <% group.each do |column| %>
      <tr>
        <td align="left" port="<%= column.name %>"><%= column.name %>   <font color="grey60"><%= column.abbreviated_data_type %></font></td>
      </tr>
    <% end %>
  <% end %>
</table>
END_HTML

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, options = {}) ⇒ TableNode

Returns a new instance of TableNode.



24
25
26
27
28
29
30
# File 'lib/pgerd/erd/table_node.rb', line 24

def initialize(table, options = {})
  @table = table

  @groups_to_hide = []
  @groups_to_hide << :id unless options.fetch(:show_id, true)
  @groups_to_hide << :timestamps unless options.fetch(:show_timestamps, true)
end

Instance Attribute Details

#groups_to_hideObject (readonly)

Returns the value of attribute groups_to_hide.



22
23
24
# File 'lib/pgerd/erd/table_node.rb', line 22

def groups_to_hide
  @groups_to_hide
end

#tableObject (readonly)

Returns the value of attribute table.



22
23
24
# File 'lib/pgerd/erd/table_node.rb', line 22

def table
  @table
end

Class Method Details

.render(table, options = {}) ⇒ Object



32
33
34
# File 'lib/pgerd/erd/table_node.rb', line 32

def self.render(table, options = {})
  new(table, options).to_html
end

Instance Method Details

#to_htmlObject



36
37
38
39
40
41
42
43
# File 'lib/pgerd/erd/table_node.rb', line 36

def to_html
  grouped_columns = @table.columns
    .reject { |column| @groups_to_hide.include? column.group }
    .group_by(&:group)
    .values

  ErbalT.new(name: @table.name, grouped_columns: grouped_columns).render(TABLE_TEMPLATE).strip
end