Class: Pgerd::Erd::TableNode
- Inherits:
-
Object
- Object
- Pgerd::Erd::TableNode
- 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
-
#groups_to_hide ⇒ Object
readonly
Returns the value of attribute groups_to_hide.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table, options = {}) ⇒ TableNode
constructor
A new instance of TableNode.
- #to_html ⇒ Object
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, = {}) @table = table @groups_to_hide = [] @groups_to_hide << :id unless .fetch(:show_id, true) @groups_to_hide << :timestamps unless .fetch(:show_timestamps, true) end |
Instance Attribute Details
#groups_to_hide ⇒ Object (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 |
#table ⇒ Object (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, = {}) new(table, ).to_html end |
Instance Method Details
#to_html ⇒ Object
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 |