Class: Umlify::Diagram
- Inherits:
-
Object
- Object
- Umlify::Diagram
- Defined in:
- lib/umlify/diagram.rb
Overview
Creates and store a yUML api string for generating diagram
-
type of @statements: 1..* String
Instance Attribute Summary collapse
-
#statements ⇒ Object
Returns the value of attribute statements.
Instance Method Summary collapse
-
#add(statement) ⇒ Object
Adds the given statement to the @diagram array Statement can either be a String or an UmlClass.
-
#compute! ⇒ Object
Sorts the statements array so that 1.
- #create(&blk) ⇒ Object
-
#get_uri ⇒ Object
Returns the yuml.me uri.
-
#initialize ⇒ Diagram
constructor
A new instance of Diagram.
Constructor Details
#initialize ⇒ Diagram
Returns a new instance of Diagram.
9 10 11 |
# File 'lib/umlify/diagram.rb', line 9 def initialize @statements = [] end |
Instance Attribute Details
#statements ⇒ Object
Returns the value of attribute statements.
7 8 9 |
# File 'lib/umlify/diagram.rb', line 7 def statements @statements end |
Instance Method Details
#add(statement) ⇒ Object
Adds the given statement to the @diagram array Statement can either be a String or an UmlClass
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/umlify/diagram.rb', line 20 def add statement # TODO: Add some sort of validation @statements << statement if statement.is_a? String if statement.is_a? UmlClass @statements << statement.to_s if statement.children statement.children.each do |child| @statements << "[#{statement.name}]^[#{child.name}]" end end unless statement.associations.empty? statement.associations.each do |name, type| unless name =~ /-/ cardinality = if statement.associations[name+'-n'] ' '+statement.associations[name+'-n'] end @statements << "[#{statement.name}]-#{name}#{cardinality}>[#{type}]" end end end end end |
#compute! ⇒ Object
Sorts the statements array so that
-
Class definitions
-
Inheritance
-
Associations
Otherwise, strange behavior can happen in the downloadd graph
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/umlify/diagram.rb', line 53 def compute! class_def = /\[[\w;?|=!]*\]/ inheritance = /\[(.*?)\]\^\[(.*?)\]/ association = /\[.*\]-.*>\[.*\]/ @statements.sort! do |x, y| if x =~ class_def and y =~ inheritance -1 elsif x =~ class_def and y =~ association -1 elsif x =~ inheritance and y =~ association -1 else 1 end end end |
#create(&blk) ⇒ Object
13 14 15 16 |
# File 'lib/umlify/diagram.rb', line 13 def create &blk instance_eval &blk self end |
#get_uri ⇒ Object
Returns the yuml.me uri
74 75 76 |
# File 'lib/umlify/diagram.rb', line 74 def get_uri uri = '/diagram/class/'+@statements.join(", ") end |