Skip to content

Instantly share code, notes, and snippets.

@devth
Created October 8, 2010 21:07
Show Gist options
  • Save devth/617546 to your computer and use it in GitHub Desktop.
Save devth/617546 to your computer and use it in GitHub Desktop.
require 'nokogiri'
# retrive unique values of category in an XML document
# doc is an Nokogiri::XML::Document
# (http://nokogiri.org/Nokogiri/XML/Document.html)
@doc.css('category').to_a.map { |c| c.content }.uniq
# css('category') # get all <category> nodes
# to_a # convert to an array
# map # invoke block on each element to pull
# the xml node's content out
# uniq # remove duplicate categories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment