| Class | Sipttra::Tracker |
| In: |
lib/webgen/sipttra_format.rb
|
| Parent: | Object |
The tracker is used to parse sipttra files and to change the sipttra data in memory.
| 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$/ |
| info | [R] | |
| nodes | [R] |
# File lib/webgen/sipttra_format.rb, line 232
232: def initialize( data = nil )
233: @nodes = []
234: @info = {}
235: parse( data ) if data
236: end
Returns all categories.
# 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
# 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.
# 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 all milestones.
# 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.
# 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 all tickets independent from their categories.
# File lib/webgen/sipttra_format.rb, line 322
322: def tickets
323: @nodes.find_all {|child| child.instance_of?( Ticket ) }
324: end