Class: RibitLinkParser

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

Instance Method Summary collapse

Instance Method Details

#parse(text, contentDoc) ⇒ Object



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/ribit/contentparser.rb', line 364

def parse( text, contentDoc )
  newContainers = Array.new
  urls = text.scan(  /\[[^\]]+\]/ )
  str = text
  urls.each do |url|
    #puts "*** str = " + str
    firstIndex = str.index( url )
    newContainers.push( TextContainer.new( str[0, firstIndex] ) )
    
    pageName = url.delete( '[]' )
    
    # if reference link like [1]
    if ( /^http:\/\/.+$/.match( pageName ) != nil )
      newContainers.push( ReferenceLinkContainer.new( pageName, contentDoc ) )
    else
      newContainers.push( RibitLinkContainer.new( pageName, contentDoc ) )
    end
    
    # take the rest of the string
    str = str[ firstIndex + url.size, str.size]
  end
  
  # take tail
  if ( str != nil and str.size() > 0 )
    #puts "*** adding the tail : " + str
    newContainers.push( TextContainer.new( str ) )
  end
  
  if ( newContainers.size == 0 )
    #puts "*** adding empty container" 
    return [TextContainer.new( text )]
  end

  return newContainers
end