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 TjpExample#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
Create a new TjpExample
object.
# File lib/taskjuggler/TjpExample.rb, line 36 def initialize @snippets = { } # Here we will store the complete example. @snippets['full text'] = [] @file = nil end
Public Instance Methods
Use this function to process the file called fileName.
# File lib/taskjuggler/TjpExample.rb, line 44 def open(fileName) @file = File.open(fileName, 'r') process @file.close end
Use this function to process the String
text.
# File lib/taskjuggler/TjpExample.rb, line 51 def parse(text) @file = StringIO.new(text) process end
This method returns the snip identified by tag.
# File lib/taskjuggler/TjpExample.rb, line 57 def to_s(tag = nil) tag = 'full text' unless tag return nil unless @snippets[tag] s = '' @snippets[tag].each { |l| s << l } s end