-# 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
- 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 != "..")
- 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