classifier: allow to sort by EXIF dates
[booh] / lib / booh / booh-lib.rb
index 3bfe17b42be81f8be8a0a0836331dfdc7e23462e..cac7b01b5e9510e01dace6c1dcdf94ebba7f4923 100644 (file)
@@ -806,6 +806,22 @@ French: Guillaume Cottenceau')),
                                               :logo => Gdk::Pixbuf.new("#{$FPATH}/images/logo.png") })
     end
 
+    def smartsort(entries, sort_criterions)
+        #- sort "entries" according to "sort_criterions" but find a good fallback for all entries without a
+        #- criterion value (still next to the item they were next to)
+        sorted_entries = sort_criterions.keys.sort { |a,b| sort_criterions[a] <=> sort_criterions[b] }
+        for i in 0 .. entries.size - 1
+            if ! sorted_entries.include?(entries[i])
+                j = i - 1
+                while j > 0 && ! sorted_entries.include?(entries[j])
+                    j -= 1
+                end
+                sorted_entries[(sorted_entries.index(entries[j]) || -1 ) + 1, 0] = entries[i]
+            end
+        end
+        return sorted_entries
+    end
+
 end
 
 class File