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.
120 121 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 |
# File 'lib/markdoc/sequence.rb', line 120 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('~') << %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. << self dest. << self unless source.eql?(dest) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def color @color end |
#comment ⇒ Object
Returns the value of attribute comment.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def comment @comment end |
#dash ⇒ Object
Returns the value of attribute dash.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def dash @dash end |
#dest ⇒ Object
Returns the value of attribute dest.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def dest @dest end |
#font ⇒ Object
Returns the value of attribute font.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def font @font end |
#label ⇒ Object
Returns the value of attribute label.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def label @label end |
#line ⇒ Object
Returns the value of attribute line.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def line @line end |
#offset ⇒ Object
Returns the value of attribute offset.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def offset @offset end |
#op ⇒ Object
Returns the value of attribute op.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def op @op end |
#options ⇒ Object
Returns the value of attribute options.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def @options end |
#row ⇒ Object
Returns the value of attribute row.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def row @row end |
#size ⇒ Object
Returns the value of attribute size.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def size @size end |
#source ⇒ Object
Returns the value of attribute source.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def source @source end |
#spacing ⇒ Object
Returns the value of attribute spacing.
116 117 118 |
# File 'lib/markdoc/sequence.rb', line 116 def spacing @spacing end |
Instance Method Details
#print ⇒ Object
154 155 156 157 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 |
# 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}" #{.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" #{.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 ⇒ Object
196 197 198 |
# File 'lib/markdoc/sequence.rb', line 196 def y offset + row*spacing end |