ruby start_with?(), end_with?()

J'ai un document avec l'objet des en-têtes d'être enfermés dans des caractères"|".

E. g. "| LINKS |"

Je veux vérifier la chaîne si elle commence et se termine avec le caractère "|" pour vérifier que le document est soumis en-tête est valide. Comment dois-je faire ?

Source:

@filetarget = " < document file location here > "

@line = ""

file = File.new(@filetarget)

while (@line = file.gets)
   if((@line.start_with?("|")) and (@line.end_with?("|")))
      puts "Putting: " + @line
   end
end

Document texte pour l'analyse:

| LINKS |

http://www.extremeprogramming.org/  <1>

http://c2.com/cgi/wiki?ExtremeProgramming  <2>

http://xprogramming.com/index.php  <3>

| COMMENTS |

* Test comment
* Test comment 2
* Test comment 3

OriginalL'auteur thotheolh | 2011-06-18