Class: Markdoc::Sequence::Message
- Inherits:
-
Object
- Object
- Markdoc::Sequence::Message
- Defined in:
- lib/markdoc/sequence.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#dash ⇒ Object
Returns the value of attribute dash.
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#font ⇒ Object
Returns the value of attribute font.
-
#label ⇒ Object
Returns the value of attribute label.
-
#line ⇒ Object
Returns the value of attribute line.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#op ⇒ Object
Returns the value of attribute op.
-
#options ⇒ Object
Returns the value of attribute options.
-
#row ⇒ Object
Returns the value of attribute row.
-
#size ⇒ Object
Returns the value of attribute size.
-
#source ⇒ Object
Returns the value of attribute source.
-
#spacing ⇒ Object
Returns the value of attribute spacing.
Instance Method Summary collapse
-
#initialize(args) ⇒ Message
constructor
A new instance of Message.
- #print ⇒ Object
- #y ⇒ Object
Constructor Details
#initialize(args) ⇒ Message
Returns a new instance of Message.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/markdoc/sequence.rb', line 122 def initialize(args) self. = [] self.label = args[:label].strip self.comment = args[:comment].strip self.op = args[:op] self.row = args[:row] # ui self.offset = args[:ui][:offset] self.color = args[:ui][:color] self.font = args[:ui][:font] self.size = args[:ui][:size] self.spacing = args[:ui][:spacing] self.line = args[:ui][:line] self.dash = args[:ui][:dash] if op.index('~') << %(stroke-dasharray="#{dash}") elsif op.index('-').nil? raise 'Message direction must be one of ->, ~>, <-, <~' end if op.index('>') self.source = args[:role1] self.dest = args[:role2] elsif op.index('<') self.source = args[:role2] self.dest = args[:role1] else raise 'Message direction must be one of ->, ~>, <-, <~' end source. << self dest. << self unless source.eql?(dest) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def color @color end |
#comment ⇒ Object
Returns the value of attribute comment.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def comment @comment end |
#dash ⇒ Object
Returns the value of attribute dash.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def dash @dash end |
#dest ⇒ Object
Returns the value of attribute dest.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def dest @dest end |
#font ⇒ Object
Returns the value of attribute font.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def font @font end |
#label ⇒ Object
Returns the value of attribute label.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def label @label end |
#line ⇒ Object
Returns the value of attribute line.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def line @line end |
#offset ⇒ Object
Returns the value of attribute offset.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def offset @offset end |
#op ⇒ Object
Returns the value of attribute op.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def op @op end |
#options ⇒ Object
Returns the value of attribute options.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def @options end |
#row ⇒ Object
Returns the value of attribute row.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def row @row end |
#size ⇒ Object
Returns the value of attribute size.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def size @size end |
#source ⇒ Object
Returns the value of attribute source.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def source @source end |
#spacing ⇒ Object
Returns the value of attribute spacing.
118 119 120 |
# File 'lib/markdoc/sequence.rb', line 118 def spacing @spacing end |
Instance Method Details
#print ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/markdoc/sequence.rb', line 158 def print role1, role2 = *(source < dest ? [source, dest] : [dest, source]) elements = [] x1 = role1.center if role1.eql?(role2) y1 = y x2 = x1 + 50 y2 = y1 + spacing elements << %(<polyline points="#{x1},#{y1} #{x2},#{y1} #{x2},#{y2} #{x1 + 5},#{y2}" fill="none" stroke-width="2" stroke-linejoin="round" stroke="#{color}" #{.join ' '}/>) elements << %(<polygon points="#{x1 + 10},#{y2 - 5} #{x1},#{y2} #{x1 + 10},#{y2 + 5}" fill="#{color}"/>) elements << %(<text x="#{x1 + 10}" y="#{y1 - 5}" font-family="#{font}" font-size="#{size}" fill="#{color}">#{label}</text>) else x2 = role2.center if role1 == source x2 -= 10 elements << %(<polygon points="#{x2},#{y - 5} #{x2 + 10},#{y} #{x2},#{y + 5}" fill="#{color}"/>) else x1 += 10 elements << %(<polygon points="#{x1},#{y - 5} #{x1 - 10},#{y} #{x1},#{y + 5}" fill="#{color}"/>) end elements << %(<line x1="#{x1}" y1="#{y}" x2="#{x2}" y2="#{y}" stroke="#{color}" stroke-width="2" #{.join ' '}/>) elements << %(<text x="#{x1 + 40}" y="#{y - 5}" font-family="#{font}" font-size="#{size}" fill="#{color}">#{label}</text>) if comment.size.positive? x = role2.prev.center + 15 elements << %(<path fill="#eeeeee" d="M#{x2 - 30},#{y + 1} L#{x2 - 30},#{y + 10} H#{x} V#{y + 2 * spacing - 25} H#{x2} V#{y + 10} H#{x2 - 20} z" />) elements << %(<text x="#{x + 5}" y="#{y + 23}" font-family="#{font}" font-size="#{size}" fill="#{color}">) split(comment).each_with_index do |line, i| elements << %(<tspan x="#{x + 5}" y="#{y + 23 + 13 * i}">#{line}</tspan>) end elements << '</text>' end end elements.join("\n") end |
#y ⇒ Object
199 200 201 |
# File 'lib/markdoc/sequence.rb', line 199 def y offset + row * spacing end |