Skip to content

Instantly share code, notes, and snippets.

@Nirma
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nirma/f28e4d6b8e4b34ff42f4 to your computer and use it in GitHub Desktop.
Save Nirma/f28e4d6b8e4b34ff42f4 to your computer and use it in GitHub Desktop.
Ruby script to clean up unused / old classes
#!/usr/local/bin/ruby
#Get Contents
file = File.open(ARGV[0], "r")
data = file.read
file.close
search_results = []
data.each_line{ |line|
output = `pt -l #{line}`
record = {:count => 0, :files => [], :name => line}
output.each_line{ |output_line|
next if output_line.match /pbxproj|Bridging-Header.h|.txt/
record[:files] << output_line
record[:count] += 1
}
search_results << record
}
search_results.sort_by!{ |hash| hash[:count]}
results = File.open(ARGV[1], "w")
output_str = ""
search_results.each{|data|
output_str += "\n\n## #{data[:name]}"
output_str += "\n#### File Count: #{data[:count]}"
output_str += "\n#### Appears in Files: \n"
data[:files].each{ |file_name|
output_str += "* " + file_name
}
output_str += "\n\n\n"
}
results.write output_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment