require 'series'
class Store
+ @@BASEPATH = '/arc/quanlib' # TODO: FIXME: configure this in a sane way
+ @@UNCLASSIFIED_CSV = @@BASEPATH + '/unclassified.csv'
+
+ def self.unclassified_csv
+ @@UNCLASSIFIED_CSV
+ end
+
def initialize
- @basepath = '/arc/quanlib' # TODO: FIXME: configure this in a sane way
@conn = nil
#@dburl = 'dbi:Pg:quanlib:localhost'
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
(efspath, efsname) = construct_efs_path(id)
- fullpath = @basepath + '/efs/' + efspath + '/' + efsname
+ fullpath = @@BASEPATH + '/efs/' + efspath + '/' + efsname
return Cover.new(nil, fullpath, mime_type)
(efspath, efsname) = construct_efs_path(efs_id)
- efspath = @basepath + '/efs/' + efspath
+ efspath = @@BASEPATH + '/efs/' + efspath
FileUtils.mkdir_p(efspath)
def populate_classifications_table
puts "Populating the Classifications table..."
first = true
- CSV.foreach(@basepath + '/csv/class.csv') do |row|
+ CSV.foreach(@@BASEPATH + '/csv/class.csv') do |row|
if first
# skip the header row
first = false
def populate_fast_table
puts "Populating the FAST table..."
first = true
- CSV.foreach(@basepath + '/csv/fast.csv') do |row|
+ CSV.foreach(@@BASEPATH + '/csv/fast.csv') do |row|
if first
first = false # skip the header row
else
def populate_series_table
puts "Populating the Series table..."
- CSV.foreach(@basepath + '/csv/series.csv') do |row|
+ CSV.foreach(@@BASEPATH + '/csv/series.csv') do |row|
id = next_id('series_id')
sqlInsert = "INSERT INTO Series (id, age, genre, grouping, code, descr) VALUES ($1, $2, $3, $4, $5, $6);"
args = [id] + row