class TaskJuggler::TjpExample

This class can extract snippets from an annotated TJP syntax file. The file does not care about the TJP syntax but the annotation lines must start with a '#' character at the begining of the line. The snippets must be enclosed by a starting line and an ending line. Each snippet must have a unique tag that can be used to retrieve the specific snip.

The following line starts a snip called 'foo': # *** EXAMPLE: foo +

The following line ends a snip called 'foo': # *** EXAMPLE: foo -

The function #to_s can be used to get the content of the snip. It takes the tag name as optional parameter. If no tag is specified, the full example without the annotation lines is returned.

Public Class Methods

new() click to toggle source

Create a new TjpExample object.

# File lib/taskjuggler/TjpExample.rb, line 35
def initialize
  @snippets = { }
  # Here we will store the complete example.
  @snippets['full text'] = []
  @file = nil

Public Instance Methods

open(fileName) click to toggle source

Use this function to process the file called fileName.

# File lib/taskjuggler/TjpExample.rb, line 43
def open(fileName)
  @file =, 'r')
parse(text) click to toggle source

Use this function to process the String text.

# File lib/taskjuggler/TjpExample.rb, line 50
def parse(text)
  @file =
to_s(tag = nil) click to toggle source

This method returns the snip identified by tag.

# File lib/taskjuggler/TjpExample.rb, line 56
def to_s(tag = nil)
  tag = 'full text' unless tag
  return nil unless @snippets[tag]

  s = ''
  @snippets[tag].each { |l| s << l }