Skip to content

Instantly share code, notes, and snippets.

@mk
Created October 21, 2008 17:00
Show Gist options
  • Save mk/18351 to your computer and use it in GitHub Desktop.
Save mk/18351 to your computer and use it in GitHub Desktop.
require 'find'
class RailsImageCounter
def self.read_images(dir = 'public/images', images = [])
Find.find(dir) { |f| images << [File.basename(f), 0, f] if File.file?(f) }
images
end
def self.count(images, dir = 'public/stylesheets')
Find.find(dir) do |f|
if File.file?(f)
contents = File.open(f, "r").to_a.join("\n")
images.each_with_index { |img, idx| images[idx][1] += 1 if contents.include?(img[0]) }
end
end
images
end
end
images = RailsImageCounter.read_images
images = RailsImageCounter.count(images, 'public/stylesheets')
images = RailsImageCounter.count(images, 'app/views')
images = RailsImageCounter.count(images, 'app/helpers')
images.sort{ |a, b| a[1] <=> b[1]}.each { |img| puts "#{img[1].to_s.ljust(4)} #{img.first.ljust(40)} #{img[2]}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment