Add support for PDF (with .jpeg cover).
[quanlib.git] / walkdir.rb
index 1dadd2e35b95974f81ad43366698c46b93dac7b9..236e3feaf7244852b4b58e780e9fdce456da6fc2 100644 (file)
@@ -31,9 +31,9 @@ class WalkDir
   def books
     result = []
     for file in @files.sort
-      if Book.canHandle?(file)
+      if Book.can_handle?(file) && (!is_duplicate?(file))
         book = Book.new(@store)
-        book.loadFromFile(file)
+        book.load_from_file(file)
         id = @store.store_book(book)
         result.push(id)
       end
@@ -41,6 +41,22 @@ class WalkDir
     return result
   end
 
+  # Duplicate versions of a text are named 
+  #   xxx_suffix.ext
+  # Where suffix is one of bis, ter, quater, quinquies
+  # for the 2nd, 3rd, 4th or 5th variant respectively.
+  def is_duplicate?(file)
+    s = file.to_s
+    suffix = ['_bis.', '_ter.', '_quater.', '_quinquies.']
+    suffix.each do |pat|
+      if s.include?(pat)
+        return true
+      end
+    end
+    
+    return false
+  end
+
   def walk(path)
     result = []
     children = Dir.entries(path)