Class Sipttra::Tracker
In: lib/webgen/sipttra_format.rb
Parent: Object
TextNode AdditionalText Comment Node Ticket Category Milestone Tracker lib/webgen/sipttra_format.rb Sipttra dot/m_7_0.png

The tracker is used to parse sipttra files and to change the sipttra data in memory.

Methods

Constants

IDENT_REGEXP = /\w[-.\w\d]*/
DATE_REGEXP = /\((\d\d\d\d-\d\d-\d\d)\)/
BELONGS_REGEXP = /\[(#{IDENT_REGEXP})\]/
TICKET_REGEXP = /^\*(?:\s(#{IDENT_REGEXP})(?=:|\s\[|\s\():?)?(?:\s#{DATE_REGEXP})?(?:\s#{BELONGS_REGEXP})?(?:$|\s(.*)$)/
CONTENT_REGEXP = /^\s\s(.*)$/
CATEGORY_REGEXP = /^(#+)\s{1,}([^(]*?)(?:\s*\((\w+)\))?\s{1,}\1$/

Attributes

info  [R] 
nodes  [R] 

Public Class methods

[Source]

     # File lib/webgen/sipttra_format.rb, line 232
232:     def initialize( data = nil )
233:       @nodes = []
234:       @info = {}
235:       parse( data ) if data
236:     end

Public Instance methods

Returns all categories.

[Source]

     # File lib/webgen/sipttra_format.rb, line 297
297:     def categories
298:       @nodes.find_all {|child| child.kind_of?( Category ) && !child.type.nil? }
299:     end

Returns the category with the given name and type.

[Source]

     # File lib/webgen/sipttra_format.rb, line 302
302:     def category( name, type )
303:       categories.find {|cat| cat.name == name && cat.type == type}
304:     end

Returns all category names.

[Source]

     # File lib/webgen/sipttra_format.rb, line 307
307:     def category_names
308:       categories.collect {|cat| cat.name}.uniq
309:     end

[Source]

     # File lib/webgen/sipttra_format.rb, line 283
283:     def check_consistency
284:       # TODO what to check?
285:     end

If Bluecloth is available text is considered to be in Markdown format and converted to HTML. Otherwise the unchanged text is returned.

[Source]

     # File lib/webgen/sipttra_format.rb, line 289
289:     def htmlize( text )
290:       require 'bluecloth'
291:       BlueCloth.new( text ).to_html
292:     rescue
293:       text
294:     end

Returns the milestone with the given name.

[Source]

     # File lib/webgen/sipttra_format.rb, line 317
317:     def milestone( name )
318:       (name.nil? ? nil : milestones.find {|ms| ms.name == name})
319:     end

Returns all milestones.

[Source]

     # File lib/webgen/sipttra_format.rb, line 312
312:     def milestones
313:       @nodes.find_all {|child| child.instance_of?( Milestone ) }
314:     end

Parses the given data and fills the tracker with information.

[Source]

     # File lib/webgen/sipttra_format.rb, line 239
239:     def parse( data )
240:       @nodes = []
241:       @info = {}
242:       level = 0
243: 
244:       if data =~ /\A---\n/m
245:         begin
246:           index = data.index( "---\n", 4 ) || 0
247:           @info = YAML.load( data[0...index] )
248:           data = data[index..-1]
249:         rescue
250:         ensure
251:           @info = {} unless @info.kind_of?( Hash )
252:         end
253:       end
254: 
255:       data.split(/\n/).each do |line|
256:         case
257:         when (m = CATEGORY_REGEXP.match( line )) && category( m[2], m[3] ).nil?
258:           @nodes << Category.new( m[2], m[3] )
259:           level = 1
260: 
261:         when level == 0
262:           @nodes  << Comment.new( line )
263: 
264:         when (m = TICKET_REGEXP.match( line )) && (milestone( m[1] ).nil? && ticket( m[1] ).nil?)
265:           if @nodes.find_all {|child| child.kind_of?( Category )}.last.type.nil?
266:             @nodes << Milestone.new( m[1], m[2], m[3], m[4] || '' )
267:           else
268:             @nodes << Ticket.new( m[1], m[2], m[3], m[4] || '' )
269:           end
270: 
271:         when (@nodes.last.kind_of?( Ticket ) || @nodes.last.kind_of?( AdditionalText )) &&
272:             (line.empty? || (m = CONTENT_REGEXP.match( line )))
273:           @nodes << AdditionalText.new( line )
274: 
275:         else
276:           @nodes << Comment.new( line )
277:         end
278:         @nodes.last.tracker = self
279:       end
280: 
281:     end

Returns the ticket with the given name.

[Source]

     # File lib/webgen/sipttra_format.rb, line 327
327:     def ticket( name )
328:       (name.nil? ? nil : tickets.find {|ticket| ticket.name == name})
329:     end

Returns all tickets independent from their categories.

[Source]

     # File lib/webgen/sipttra_format.rb, line 322
322:     def tickets
323:       @nodes.find_all {|child| child.instance_of?( Ticket ) }
324:     end

Returns all tickets for the category name independent from the category type.

[Source]

     # File lib/webgen/sipttra_format.rb, line 332
332:     def tickets_for_category( name )
333:       tickets.select {|t| t.category.name == name}
334:     end

Returns a string representation of the tracker which can later be used by parse .

[Source]

     # File lib/webgen/sipttra_format.rb, line 337
337:     def to_s
338:       @info.to_yaml.sub( /^---\s*\n/m, '' ) + "\n\n" + @nodes.collect {|line| line.to_line}.join( "\n" )
339:     end

[Validate]