Created
November 23, 2010 03:14
-
-
Save afair/711172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
class Cleaner | |
def read | |
f = File.open("nelson.xml") | |
@doc = Nokogiri::XML(f) | |
f.close | |
end | |
def save | |
f = File.open("nelson-new.xml", 'w') | |
f.puts @doc | |
f.close | |
end | |
def find | |
list = [] | |
# Find each dictionary item and loop through it | |
@doc.xpath('/plist/dict/dict/dict').each do |node| | |
hash = {} | |
last_key = nil | |
# Stuff the key value pairs in to hash. We know a key is followed by | |
# a value, so we'll just skip blank nodes, save the key, then when we | |
# find the value, add it to the hash | |
node.children.each do |child| | |
next if child.blank? # Don't care about blank nodes | |
if child.name == 'key' | |
# Save off the key | |
last_key = child.text | |
else | |
# Use the key we saved | |
hash[last_key] = child.text | |
end | |
end | |
if hash['Location'] =~ /\/mp3\/mp3\// | |
puts hash['Location'] | |
node.remove | |
end | |
#list << hash # push on to our list | |
end | |
end | |
end | |
c = Cleaner.new | |
c.read | |
c.find | |
c.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment