Class: TaskJuggler::TjpExample
Overview
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.
Instance Method Summary collapse
-
#initialize ⇒ TjpExample
constructor
Create a new TjpExample object.
-
#open(fileName) ⇒ Object
Use this function to process the file called fileName.
-
#parse(text) ⇒ Object
Use this function to process the String text.
-
#to_s(tag = nil) ⇒ Object
This method returns the snip identified by tag.
Constructor Details
#initialize ⇒ TjpExample
Create a new TjpExample object.
36 37 38 39 40 41 |
# File 'lib/taskjuggler/TjpExample.rb', line 36 def initialize @snippets = { } # Here we will store the complete example. @snippets['full text'] = [] @file = nil end |
Instance Method Details
#open(fileName) ⇒ Object
Use this function to process the file called fileName.
44 45 46 47 48 |
# File 'lib/taskjuggler/TjpExample.rb', line 44 def open(fileName) @file = File.open(fileName, 'r') process @file.close end |
#parse(text) ⇒ Object
Use this function to process the String text.
51 52 53 54 |
# File 'lib/taskjuggler/TjpExample.rb', line 51 def parse(text) @file = StringIO.new(text) process end |
#to_s(tag = nil) ⇒ Object
This method returns the snip identified by tag.
57 58 59 60 61 62 63 64 |
# 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 |