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.
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/markdoc/sequence.rb', line 224 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.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def attributes @attributes end |
#input ⇒ Object
Returns the value of attribute input.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def input @input end |
#messages ⇒ Object
Returns the value of attribute messages.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def @messages end |
#output ⇒ Object
Returns the value of attribute output.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def output @output end |
#roles ⇒ Object
Returns the value of attribute roles.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def roles @roles end |
#rows ⇒ Object
Returns the value of attribute rows.
222 223 224 |
# File 'lib/markdoc/sequence.rb', line 222 def rows @rows end |
Instance Method Details
#find(id) ⇒ Object
237 238 239 |
# File 'lib/markdoc/sequence.rb', line 237 def find(id) roles.detect { |role| role.id == id.strip } or raise("Non-declared role: #{id}") end |
#height ⇒ Object
298 299 300 301 302 |
# File 'lib/markdoc/sequence.rb', line 298 def height attributes[:message][:offset] + attributes[:message][:spacing] * rows + attributes[:diagram][:offsety] * 2 end |
#parse ⇒ Object
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 291 292 |
# File 'lib/markdoc/sequence.rb', line 241 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.positive? 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
294 295 296 |
# File 'lib/markdoc/sequence.rb', line 294 def print format(template, width: width, height: height, content: (roles + ).map(&:print).join("\n")) end |
#width ⇒ Object
304 305 306 307 |
# File 'lib/markdoc/sequence.rb', line 304 def width (attributes[:role][:spacing] + attributes[:role][:width]) * roles.size + attributes[:diagram][:offsetx] end |