Class: Markdoc::Sequence::Diagram
- Inherits:
-
Object
- Object
- Markdoc::Sequence::Diagram
- Defined in:
- lib/markdoc/sequence.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#input ⇒ Object
Returns the value of attribute input.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#output ⇒ Object
Returns the value of attribute output.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
- #find(id) ⇒ Object
- #height ⇒ Object
-
#initialize(input, options = {}) ⇒ Diagram
constructor
A new instance of Diagram.
- #parse ⇒ Object
- #print ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(input, options = {}) ⇒ Diagram
Returns a new instance of Diagram.
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/markdoc/sequence.rb', line 222 def initialize(input, = {}) self.input = input self.output = [] self.roles = [] self. = [] self.rows = 0 self.attributes = DEFAULTS.dup .each do |key, value| attributes.merge!(key => value) end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def attributes @attributes end |
#input ⇒ Object
Returns the value of attribute input.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def input @input end |
#messages ⇒ Object
Returns the value of attribute messages.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def end |
#output ⇒ Object
Returns the value of attribute output.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def output @output end |
#roles ⇒ Object
Returns the value of attribute roles.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def roles @roles end |
#rows ⇒ Object
Returns the value of attribute rows.
220 221 222 |
# File 'lib/markdoc/sequence.rb', line 220 def rows @rows end |
Instance Method Details
#find(id) ⇒ Object
235 236 237 |
# File 'lib/markdoc/sequence.rb', line 235 def find(id) roles.detect{|role| role.id == id.strip} or raise("Non-declared role: #{id}") end |
#height ⇒ Object
300 301 302 303 304 |
# File 'lib/markdoc/sequence.rb', line 300 def height attributes[:message][:offset] + attributes[:message][:spacing] * rows + attributes[:diagram][:offsety] * 2 end |
#parse ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/markdoc/sequence.rb', line 239 def parse input.split("\n").each do |line| next if line.strip.empty? if matches = line.match(/^(?<id>[a-zA-Z0-9_ \t]+) *= *(?<label>[a-zA-Z0-9_ \t]+)/) # User = Actor roles << Role.new( id: matches[:id], label: matches[:label], column: roles.size, diagram: attributes[:diagram], ui: attributes[:role] ) elsif matches = line.match(/^(?<role1>[a-zA-Z0-9_ \t]+) *(?<op>[<\-~>]{2}) *(?<role2>[a-zA-Z0-9_ \t]+):(?<label>[^#]+)#?(?<comment>.*)/) # User -> Web : Login << Message.new( role1: find(matches[:role1]), role2: find(matches[:role2]), row: rows, op: matches[:op], label: matches[:label], comment: matches[:comment], diagram: attributes[:diagram], ui: attributes[:message] ) self.rows += 1 # comment takes 1 more row self.rows += 1 if matches[:comment].length > 0 elsif matches = line.match(/^(?<role>[a-zA-Z0-9_ \t]+) *:(?<label>[^#]+)#?(?<comment>.*)/) # Web : Save the form << Message.new( role1: find(matches[:role]), role2: find(matches[:role]), row: rows, op: '->', label: matches[:label], comment: matches[:comment], diagram: attributes[:diagram], ui: attributes[:message] ) # self message takes 2 rows self.rows += 2 end end prev = nil roles.each do |succ| succ.prev = prev prev.succ = succ if prev prev = succ end end |
#print ⇒ Object
292 293 294 295 296 297 298 |
# File 'lib/markdoc/sequence.rb', line 292 def print template % { width: width, height: height, content: (roles + ).map(&:print).join("\n") } end |
#width ⇒ Object
306 307 308 309 |
# File 'lib/markdoc/sequence.rb', line 306 def width (attributes[:role][:spacing] + attributes[:role][:width]) * roles.size + attributes[:diagram][:offsetx] end |