Thursday, June 13, 2013

[Rails] Re: Good Rubyistic way Looking for nokogiri program

Find the below code :

require 'nokogiri'

doc = Nokogiri::HTML(<<-eohl)
<div>
<dt>
Test 1
</dt>
<dd>
</dd>
<dt>
Test 2
</dt>
<dd>
foo
</dd>
</div>
eohl


doc.search('div').children.reject(&:text?).map{|n| n.name if
!n.child.to_str.strip.empty? }.compact
# => ["dt", "dt", "dd"]

Any short technique to generate the array `["dt", "dt", "dd"]` ?

Thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/50c806602f653550e47a22100e408b1d%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate