Created
September 21, 2012 03:54
-
-
Save jkubicek/3759637 to your computer and use it in GitHub Desktop.
Sort Obj-C properties and methods
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/ruby | |
def sortProperties(lines) | |
props = Hash.new | |
lines.each {|line| | |
props[line.gsub(/@.+?(\w+?);[^;]*?$/, "\\1")] = line | |
} | |
sortedKeys = props.keys.sort | |
output = Array.new | |
sortedKeys.each { |key| | |
output << props[key] | |
} | |
return output | |
end | |
def sortMethods(lines) | |
methods = Hash.new | |
lines.each {|line| | |
methods[line.gsub(/^[-+ ]+\([\w \*]+\) *(.+)/, "\\1")] = line | |
} | |
sortedKeys = methods.keys.sort | |
output = Array.new | |
sortedKeys.each { |key| | |
output << methods[key] | |
} | |
return output | |
end | |
lines = Array.new | |
ARGF.each {|line| | |
lines << line | |
} | |
classMethods = Array.new | |
instanceMethods = Array.new | |
properties = Array.new | |
lines.each {|line| | |
if line.start_with?("+") | |
classMethods << line | |
elsif line.start_with?("-") | |
instanceMethods << line | |
elsif line.start_with?("@property") | |
properties << line | |
end | |
} | |
puts "\n\n// Class Methods\n" | |
puts sortMethods(classMethods) | |
puts "\n\n// Properties\n" | |
puts sortProperties(properties) | |
puts "\n\n// Instance Methods\n" | |
puts sortMethods(instanceMethods) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment