dlister 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dlister/dir_list.rb +18 -11
- data/lib/dlister/version.rb +1 -1
- metadata +1 -1
data/lib/dlister/dir_list.rb
CHANGED
@@ -46,22 +46,29 @@ module Dlister
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def entry_sort entries
|
49
|
-
|
49
|
+
entries.sort do |a, b|
|
50
|
+
sort_precendence a, b
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sort_precendence a, b
|
55
|
+
order = [:directory, :executable, :file, :link, :invalid_link, :not_found]
|
50
56
|
|
51
|
-
|
52
|
-
|
57
|
+
entry_a, attr_a = a
|
58
|
+
entry_b, attr_b = b
|
53
59
|
|
54
|
-
|
60
|
+
rtype_a, rtype_b = attr_a[:real_type], attr_b[:real_type]
|
55
61
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
+
rtype_sort = order.index(rtype_a) <=> order.index(rtype_b)
|
63
|
+
|
64
|
+
if rtype_sort == 0 then
|
65
|
+
if entry_a =~ /^\d/ && entry_b =~ /^\d/ then
|
66
|
+
entry_a.to_i <=> entry_b.to_i
|
62
67
|
else
|
63
|
-
|
68
|
+
entry_a <=> entry_b
|
64
69
|
end
|
70
|
+
else
|
71
|
+
rtype_sort
|
65
72
|
end
|
66
73
|
end
|
67
74
|
|
data/lib/dlister/version.rb
CHANGED