Class: Markdoc::Sequence::Role

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/markdoc/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Role

Returns a new instance of Role.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/markdoc/sequence.rb', line 46

def initialize(args)
  self.messages = []
  self.id = args[:id].strip
  self.label = args[:label].strip

  # ui settings
  self.column = args[:column]
  self.offsetx = args[:diagram][:offsetx]
  self.offsety = args[:diagram][:offsety]
  self.border = args[:ui][:border]
  self.fill = args[:ui][:fill]
  self.radius = args[:ui][:radius]
  self.spacing = args[:ui][:spacing]
  self.width = args[:ui][:width]
  self.height = args[:ui][:height]
  self.line = args[:ui][:line]
  self.font = args[:ui][:font]
end

Instance Attribute Details

#borderObject

Returns the value of attribute border.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def border
  @border
end

#columnObject

Returns the value of attribute column.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def column
  @column
end

#fillObject

Returns the value of attribute fill.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def fill
  @fill
end

#fontObject

Returns the value of attribute font.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def font
  @font
end

#heightObject

Returns the value of attribute height.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def height
  @height
end

#idObject

Returns the value of attribute id.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def id
  @id
end

#labelObject

Returns the value of attribute label.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def label
  @label
end

#lineObject

Returns the value of attribute line.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def line
  @line
end

#messagesObject

Returns the value of attribute messages.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def messages
  @messages
end

#offsetxObject

Returns the value of attribute offsetx.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def offsetx
  @offsetx
end

#offsetyObject

Returns the value of attribute offsety.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def offsety
  @offsety
end

#prevObject

Returns the value of attribute prev.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def prev
  @prev
end

#radiusObject

Returns the value of attribute radius.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def radius
  @radius
end

#spacingObject

Returns the value of attribute spacing.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def spacing
  @spacing
end

#succObject

Returns the value of attribute succ.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def succ
  @succ
end

#widthObject

Returns the value of attribute width.



42
43
44
# File 'lib/markdoc/sequence.rb', line 42

def width
  @width
end

Instance Method Details

#<=>(other) ⇒ Object



65
66
67
# File 'lib/markdoc/sequence.rb', line 65

def <=>(other)
  column <=> other.column
end

#centerObject



84
85
86
# File 'lib/markdoc/sequence.rb', line 84

def center
  x + width / 2
end


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/markdoc/sequence.rb', line 96

def print
  elements = []
  case type
  when :actor
    elements << %[<g transform="translate(#{x + 10},0)"><path d="M74,64 a30,30 0 0,0 -27,-27 a16,18 0 1,0 -16,0 a30,30 0, 0,0 -27,27 z" stroke-width="#{line}" fill="#{fill}" stroke="#{border}"/></g>]
    elements << %(<text x="#{x + 46 - 2 * id.size}" y="#{y + height - 5}" font-family="#{font}" font-size="12" fill="#{border}">#{id}</text>)
  else
    elements << %(<rect fill="#{fill}" stroke="#{border}" rx="#{radius}" ry="#{radius}" x="#{x}" y="#{y}" width="#{width}" height="#{height}" stroke-width="#{line}"/>)
    elements << %(<text x="#{x + 10}" y="#{y + 20}" font-family="#{font}" font-size="12" fill="#{border}">#{label}</text>)
  end

  x1 = center
  y1 = offsety + height
  x2 = center
  y2 = messages.last.y + 10
  elements << %(<line x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}" stroke="#{border}" stroke-width="#{line}"/>)

  elements.join("\n")
end

#typeObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/markdoc/sequence.rb', line 69

def type
  case label
  when /actor/i
    :actor
  when /database/i
    :database
  when /site|web/i
    :website
  when /application|system/i
    :system
  else
    :component
  end
end

#xObject



88
89
90
# File 'lib/markdoc/sequence.rb', line 88

def x
  offsetx + column * (width + spacing)
end

#yObject



92
93
94
# File 'lib/markdoc/sequence.rb', line 92

def y
  offsety
end