class Architect::Association

Association between two classes

Constants

TYPES

Public Class Methods

new(node1, node2, markup="->") click to toggle source
Calls superclass method
# File lib/architect/association.rb, line 18
def initialize(node1, node2, markup="->")
  super node1, node2
  @attributes = parse_markup(markup)
end

Public Instance Methods

get_arrow(string) click to toggle source

Return the type of arrow contained in the markup

# 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) click to toggle source

Remove the arrow to get label

# 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) click to toggle source
# File lib/architect/association.rb, line 54
def get_linestyle(string)
  if /-\.-/.match(string) == nil
    return "solid"
  else
    return "dashed"
  end
end
graph(g) click to toggle source

Add associations to Graphviz

# File lib/architect/association.rb, line 63
def graph(g)
  g.add_edges(@node1.graphnode, @node2.graphnode, @attributes)
end
parse_markup(markup) click to toggle source
# 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