我想找到一种方法来使用以下 Ruby 代码获取 HTML 结果(下面进一步提到)Nokogiri http://github.com/tenderlove/nokogiri/tree/master:
require 'rubygems'
require 'nokogiri'
value = Nokogiri::HTML.parse(<<-HTML_END)
"<html>
<body>
<p id='1'>A</p>
<p id='2'>B</p>
<h1>Bla</h1>
<p id='3'>C</p>
<p id='4'>D</p>
<p id='5'>E</p>
</body>
</html>"
HTML_END
# The selected-array is given by the application.
# It consists of a sorted array with all ids of
# <p> that need to be enclosed by the <div>
selected = ["2","3","4"]
first_p = selected.first
last_p = selected.last
#
# WHAT RUBY CODE DO I NEED TO INSERT HERE TO GET
# THE RESULTING HTML AS SEEN BELOW?
#