class Markdoc::Sequence::Message
Attributes
color[RW]
comment[RW]
dash[RW]
dest[RW]
font[RW]
label[RW]
line[RW]
offset[RW]
op[RW]
options[RW]
row[RW]
size[RW]
source[RW]
spacing[RW]
Public Class Methods
new(args)
click to toggle source
# File lib/markdoc/sequence.rb, line 120 def initialize(args) self.options = [] 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('~') options << %Q[stroke-dasharray="#{dash}"] elsif op.index('-').nil? raise "Message direction must be one of ->, ~>, <-, <~" end if op.index('>') self.source, self.dest = args[:role1], args[:role2] elsif op.index('<') self.source, self.dest = args[:role2], args[:role1] else raise "Message direction must be one of ->, ~>, <-, <~" end source.messages << self dest.messages << self unless source.eql?(dest) end
Public Instance Methods
print()
click to toggle source
# File lib/markdoc/sequence.rb, line 154 def print role1, role2 = *(source < dest ? [source, dest] : [dest, source]) elements = [] if role1.eql?(role2) x1 = role1.center y1 = y x2 = x1 + 50 y2 = y1 + spacing elements << %Q(<polyline points="#{x1},#{y1} #{x2},#{y1} #{x2},#{y2} #{x1+5},#{y2}" fill="none" stroke-width="2" stroke-linejoin="round" stroke="#{color}" #{options.join ' '}/>) elements << %Q(<polygon points="#{x1+10},#{y2-5} #{x1},#{y2} #{x1+10},#{y2+5}" fill="#{color}"/>) elements << %Q(<text x="#{x1+10}" y="#{y1-5}" font-family="#{font}" font-size="#{size}" fill="#{color}">#{label}</text>) else x1 = role1.center x2 = role2.center if role1 == source x2 -= 10 elements << %Q(<polygon points="#{x2},#{y-5} #{x2+10},#{y} #{x2},#{y+5}" fill="#{color}"/>) else x1 += 10 elements << %Q(<polygon points="#{x1},#{y-5} #{x1-10},#{y} #{x1},#{y+5}" fill="#{color}"/>) end elements << %Q(<line x1="#{x1}" y1="#{y}" x2="#{x2}" y2="#{y}" stroke="#{color}" stroke-width="2" #{options.join ' '}/>) elements << %Q(<text x="#{x1+40}" y="#{y-5}" font-family="#{font}" font-size="#{size}" fill="#{color}">#{label}</text>) if comment.size > 0 x = role2.prev.center + 15 elements << %Q(<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 << %Q(<text x="#{x+5}" y="#{y+23}" font-family="#{font}" font-size="#{size}" fill="#{color}">) split(comment).each_with_index do |line, i| elements << %Q(<tspan x="#{x+5}" y="#{y+23+13*i}">#{line}</tspan>) end elements << '</text>' end end elements.join("\n") end
y()
click to toggle source
# File lib/markdoc/sequence.rb, line 196 def y offset + row*spacing end
Private Instance Methods
split(text, max = 35)
click to toggle source
# File lib/markdoc/sequence.rb, line 202 def split(text, max = 35) ary = [] line = '' text.split.each do |word| if (line + word).length < max line << ' ' << word else ary << line line = word end end ary << line if line.length > 0 ary end