Class: UnformattedContentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ribit/contentparser.rb

Instance Method Summary collapse

Instance Method Details

#parse(text, contentDoc) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/ribit/contentparser.rb', line 291

def parse( text, contentDoc )
  preStarted = false
  newContainers = Array.new
  
  currentContainer = TextContainer.new
  newContainers.push( currentContainer )
  
  # NOTE: that lines contain line feeds
  text.each_line do |line|
    preLine = /^ /.match( line ) != nil
    
    if ( preLine == true and preStarted == false )
      currentContainer  = UnformattedContentContainer.new
      newContainers.push( currentContainer )
      preStarted = true
      
    elsif ( preLine == false and  preStarted == true )
      currentContainer = TextContainer.new
      newContainers.push( currentContainer )        
      preStarted = false
      
    end
    
    if ( preStarted )
      # drop first character that is space
      currentContainer << line[1, line.size()]
    else
      currentContainer << line
    end
    
  end
  
  return newContainers
end