Class: Architect::Association
Overview
Association between two classes
Constant Summary collapse
- TYPES =
{ "<>" => "odiamond", "+" => "odiamond", "++" => "diamond", "" => "none", ">" => "vee", "^" => "empty" }
Instance Attribute Summary
Attributes inherited from Edge
Instance Method Summary collapse
-
#get_arrow(string) ⇒ Object
Return the type of arrow contained in the markup.
-
#get_label(string) ⇒ Object
Remove the arrow to get label.
- #get_linestyle(string) ⇒ Object
-
#graph(g) ⇒ Object
Add associations to Graphviz.
-
#initialize(node1, node2, markup = "->") ⇒ Association
constructor
A new instance of Association.
- #parse_markup(markup) ⇒ Object
Constructor Details
#initialize(node1, node2, markup = "->") ⇒ Association
Returns a new instance of Association.
18 19 20 21 |
# File 'lib/architect/association.rb', line 18 def initialize(node1, node2, markup="->") super node1, node2 @attributes = parse_markup(markup) end |
Instance Method Details
#get_arrow(string) ⇒ Object
Return the type of arrow contained in the markup
36 37 38 39 40 41 42 43 |
# File 'lib/architect/association.rb', line 36 def get_arrow(string) tokens = /([<>+\^]+)/.match(string) if tokens == nil return "none" else return TYPES[tokens[0]] end end |
#get_label(string) ⇒ Object
Remove the arrow to get label
46 47 48 49 50 51 52 |
# File 'lib/architect/association.rb', line 46 def get_label(string) return "" if string == nil TYPES.keys.each do |arrow| string = string.gsub(arrow, "") end return string end |
#get_linestyle(string) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/architect/association.rb', line 54 def get_linestyle(string) if /-\.-/.match(string) == nil return "solid" else return "dashed" end end |
#graph(g) ⇒ Object
Add associations to Graphviz
63 64 65 |
# File 'lib/architect/association.rb', line 63 def graph(g) g.add_edges(@node1.graphnode, @node2.graphnode, @attributes) end |
#parse_markup(markup) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/architect/association.rb', line 23 def parse_markup(markup) matches = /(.*)-\.-(.*)/.match(markup) matches = /(.*)-(.*)/.match(markup) if matches == nil left = matches[1] right = matches[2] style = get_linestyle(markup) {arrowhead: get_arrow(right), arrowtail: get_arrow(left), headlabel: " " + get_label(right) + " ", taillabel: " " + get_label(left) + " ", dir: "both", style: style} end |