-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsortscript.rb
48 lines (42 loc) · 928 Bytes
/
sortscript.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
#!/usr/bin/env ruby
require 'date'
fileName = ARGV[0]
originalFile = File.open(fileName, "r")
split = originalFile.read.split("\n")
originalFile.close
def sortDate(a,b)
aSplit = a.split("/");
bSplit = b.split("/");
yearCompare = aSplit[2].to_i <=> bSplit[2].to_i
if yearCompare != 0
return yearCompare
else
monthCompare = aSplit[0].to_i <=> bSplit[0].to_i
if monthCompare != 0
return monthCompare
else
return aSplit[1].to_i <=> bSplit[1].to_i
end
end
end
sort = split.sort { |a,b|
dateA = a
if a.rpartition(",")[-1].length == 1
dateA = a.rpartition(",")[-3].rpartition(",")[-1]
else
dateA = a.rpartition(",")[-1]
end
dateB = b
if b.rpartition(",")[-1].length == 1
dateB = b.rpartition(",")[-3].rpartition(",")[-1]
else
dateB = b.rpartition(",")[-1]
end
sortDate(dateA,dateB)
}
puts sort
puts fileName
newFile = File.open(fileName, "w")
newFile.puts sort
newFile.close
puts "done!"