Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UIKitImage
- attr_accessor :iphone1x, :iphone2x, :ipad, :baseName, :resourcePath, :fullPath
- def to_s
- kinds = Array.new
- kinds << "@1x" if @iphone1x == true
- kinds << "@2x" if @iphone2x == true
- kinds << "~ipad" if @ipad == true
- return @baseName + " " + kinds.join(" ")
- end
- end
- class NilClass
- def length
- 0
- end
- end
- class String
- def substr_from(idx)
- self[idx, self.length-idx]
- end
- end
- resourcesDir = "/Users/dave/Developer/UIKit/Resources/"
- kinds = {
- "~iphone" => "iphone1x",
- "@2x" => "iphone2x",
- "@2x~iphone" => "iphone2x",
- "~iphone@2x" => "iphone2x",
- "~ipad" => "ipad"
- }
- images = Hash.new
- resources = Dir.glob("#{resourcesDir}**/*.png");
- resources.each do|file|
- basename = File.basename(file, ".png")
- # attempt to find the suffix used by the file
- property = nil
- suffix = nil
- kinds.keys.sort.each do|potentialSuffix|
- if basename.downcase.end_with?(potentialSuffix) then
- if potentialSuffix.length > suffix.length then
- property = kinds[potentialSuffix]
- suffix = potentialSuffix
- end
- end
- end
- # figure out the actual basename
- property = "iphone1x" if property == nil
- basename = basename[0, basename.length-suffix.length] if suffix.length > 0
- # retrieve the image object
- image = images[basename]
- if image == nil then
- image = UIKitImage.new
- image.fullPath = file
- image.baseName = basename
- image.resourcePath = file.substr_from(resourcesDir.length)
- if basename == 126 or basename == 64 then
- puts "ERROR: #{file} #{basename} #{suffix}"
- end
- images[basename] = image
- end
- # set the property value
- image.send("#{property}=", true)
- end
- images.keys.sort.each do|basename|
- puts images[basename]
- end
Add Comment
Please, Sign In to add comment