-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_property_method.rb
58 lines (47 loc) · 1.01 KB
/
sort_property_method.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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)