Also, drop duplicate PDF and EPUB holdings, preferring EPUB.
require 'zip'
require 'author'
+require 'classification'
require 'cover'
require 'store'
result.push(seriesInfo.join(' '))
end
+ classification = nil
+ if nil != @classification_id
+ classification = @store.load_classification(@classification_id)
+ end
+ if nil != classification
+ if nil != classification.ddc
+ result.push('Dewey: ' + classification.ddc.to_s)
+ end
+ if nil != classification.lcc
+ result.push('LCC: ' + classification.lcc.to_s)
+ end
+ end
+
return result.join('<br/>')
end
--- /dev/null
+
+class Classification
+ def initialize(ddc, lcc, author_grouping, author, title_grouping, title)
+ @id = nil
+ @ddc = ddc
+ @lcc = lcc
+ @author_grouping = author_grouping
+ @author = author
+ @title_grouping = title_grouping
+ @title = title
+ end
+
+ def id
+ @id
+ end
+ def id=(value)
+ @id = value
+ end
+
+ def ddc
+ @ddc
+ end
+ def lcc
+ @lcc
+ end
+ def author_grouping
+ @author_grouping
+ end
+ def author
+ @author
+ end
+ def
+
+ def inspect
+ data = []
+
+ if nil != @ddc
+ data.push('Dewey=' + @ddc.to_s)
+ end
+ if nil != @lcc
+ data.push('LCC=' + @lcc.to_s)
+ end
+ if nil != @author_grouping
+ data.push('author_grouping=' + @author_grouping.to_s)
+ end
+ if nil != @author
+ data.push('author=' + @author.to_s)
+ end
+ if nil != @title_grouping
+ data.push('title_grouping=' + @title_grouping.to_s)
+ end
+ if nil != @title
+ data.push('title=' + @title)
+ end
+
+ return '(Classification:' + data.join(',') + ')'
+ end
+
+ def to_s
+ inspect
+ end
+
+ protected
+ def reading_to_sort_order(reading_order)
+ sort_order = reading_order
+
+ parts = reading_order.split(' ')
+ if parts.length > 1
+ sort_order = parts[-1] + ', ' + parts[0..-2].join(' ')
+ end
+
+ return sort_order
+ end
+end
+
require 'fileutils'
-require 'store'
+require 'store'
class Page
def initialize(store)
CREATE TABLE Authors (
id INTEGER PRIMARY KEY,
grouping VARCHAR(64),
- reading VARCHAR(128),
- sort VARCHAR(128)
+ reading VARCHAR(196),
+ sort VARCHAR(196)
);
EOS
return nil
end
+ def load_classification(id)
+ sql = "SELECT ddc, lcc, author_grouping, author_sort, title_grouping, title "
+ sql += " FROM Classifications WHERE id=$1"
+ @conn.exec_params(sql, [id]) do |rs|
+ if rs.ntuples > 0
+ row = rs[0]
+ ddc = row['ddc']
+ lcc = row['lcc']
+ author_grouping = row['author_grouping']
+ author = row['author_sort']
+ title_grouping = row['title_grouping']
+ title = row['title']
+
+ result = Classification.new(ddc, lcc, author_grouping, author, title_grouping, title)
+ result.id = id
+ return result
+ end
+ end
+
+ return nil
+ end
+
def load_cover(id)
if nil == id
return nil
def books
result = []
- for file in @files.sort
+ @files = remove_duplicates(@files)
+ for file in @files.sort()
if Book.can_handle?(file) && (!is_duplicate?(file))
book = Book.new(@store)
book.load_from_file!(file)
return false
end
+ def remove_duplicates(files)
+ unique = {}
+ for file in files
+ if Book.can_handle?(file)
+ key = File.dirname(file) + '/' + File.basename(file, '.*')
+ if unique.has_key?(key)
+ new_ext = File.extname(file)
+ old_ext = File.extname(unique[key])
+ if ('.pdf' == old_ext) && ('.epub' == new_ext)
+ # Prefer EPUB over PDF
+ puts 'REPLACED ' + unique[key].to_s + ' with ' + file.to_s
+ unique[key] = file
+ else
+ puts 'DROPPED ' + file.to_s + " because it's superceded by " + unique[key].to_s
+ end
+ else
+ unique[key] = file
+ end
+ end
+ end
+
+ return unique.values
+ end
+
def walk(path)
result = []
children = Dir.entries(path)