X-Git-Url: http://jaekl.net/gitweb/?p=quanlib.git;a=blobdiff_plain;f=walkdir.rb;h=b00645545fa984b5fbef17b09b45513957ab6f69;hp=035752f05d48785d10db87d3b6e6bf91abe855a2;hb=HEAD;hpb=e9d890ae4d346ce3abe93a8db94d3a3ddf9819d9 diff --git a/walkdir.rb b/walkdir.rb deleted file mode 100644 index 035752f..0000000 --- a/walkdir.rb +++ /dev/null @@ -1,56 +0,0 @@ -# Walk the directory (and subdirectories), identifying books. -# -# Expected format: -# .../AuthorName/Title_of_the_Awesome_Book.ext -# -# Author is given as FirstLast. For example, -# Robert Anson Heinlein is RoberHeinlein, and -# JKRowling is JoanneRowling. -# -# Book titles have spaces replaced with underscores, -# and punctuation [,!?'] replaced with hyphens. -# -# If the book forms part of a series, then an all-capitals -# series designator, followed by a numeric volume number, -# followed by an underscore, is prefixed to the name. -# For example, Hardy Boys' volume 1, The Tower Treasure, -# is rendered as .../FranklinDixon/HB001_The_Tower_Treasure.epub -# and Mrs. Pollifax volume 6, On the China Station, is -# .../DorothyGilman/P06_On_the_China_Station.epub. - -require 'book' - -class WalkDir - def initialize(root) - @root = root - @files = walk(@root) - end - - def books - result = [] - for file in @files.sort - if Book.canHandle?(file) - book = Book.new(file) - result.push(book) - end - end - return result - end - - def walk(path) - result = [] - children = Dir.entries(path) - for child in children - fullName = (path.chomp("/")) + "/" + child - if (File.directory?(fullName)) and (child != ".") and (child != "..") and (!File.symlink?(fullName)) - sub = walk(fullName) - if (sub != nil) and (sub.length > 0) - result.concat(sub) - end - elsif (! File.directory?(fullName)) - result.push(fullName) - end - end - return result - end -end