projects
/
quanlib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add `arrived` attribute (file creation timestamp) to books table.
[quanlib.git]
/
book.rb
diff --git
a/book.rb
b/book.rb
index d7135690d4d60514f4c900d59dc76698d3eb164d..2b93f4b574c9c45738a3a95a2c0b4f1697083d1c 100644
(file)
--- a/
book.rb
+++ b/
book.rb
@@
-10,7
+10,9
@@
require_relative 'store'
class Book
@@DC_NS_URL = 'http://purl.org/dc/elements/1.1/'
class Book
@@DC_NS_URL = 'http://purl.org/dc/elements/1.1/'
+ @@SERIES_AND_VOLUME_REGEX = /^([A-Z]+)([0-9]+(\.[0-9]+)?)$/
+ attr_accessor :arrived
attr_accessor :author
attr_accessor :classification_id
attr_accessor :cover
attr_accessor :author
attr_accessor :classification_id
attr_accessor :cover
@@
-49,6
+51,18
@@
class Book
return false
end
return false
end
+ def self.grouping_for_title(title)
+ result = title
+
+ '\'",!#'.split('').each do |c|
+ result = result.gsub(c, '-')
+ end
+ result = result.gsub(/: */, '--')
+ result = result.gsub(' ', '_')
+
+ result
+ end
+
def heading
result = []
def heading
result = []
@@
-159,7
+173,7
@@
class Book
vol = nil
first = arr[0]
vol = nil
first = arr[0]
- matchData = (arr[0]).match(
/^([A-Z]+)([0-9]+)$/
)
+ matchData = (arr[0]).match(
@@SERIES_AND_VOLUME_REGEX
)
if nil != matchData
capt = matchData.captures
series = capt[0]
if nil != matchData
capt = matchData.captures
series = capt[0]
@@
-174,6
+188,15
@@
class Book
title = arr.join(' ')
title = arr.join(' ')
+ bare_title_grouping = title_grouping
+ .split('_')
+ .reject { |part| part.match(@@SERIES_AND_VOLUME_REGEX) }
+ .join('_')
+
+ unless bare_title_grouping == Book.grouping_for_title(title)
+ puts "WARNING: title_grouping mismatch: #{bare_title_grouping.inspect} vs. #{Book.grouping_for_title(title).inspect}"
+ end
+
return series, vol, title
end
return series, vol, title
end
@@
-202,6
+225,8
@@
class Book
scan_pdf!(file_name)
end
scan_pdf!(file_name)
end
+ @arrived = File.ctime(file_name)
+
@classification_id = @store.find_classification(@author.grouping, File.basename(file_name, '.*'))
# TODO: Fix horrible hard-coded strings and paths
@classification_id = @store.find_classification(@author.grouping, File.basename(file_name, '.*'))
# TODO: Fix horrible hard-coded strings and paths