alexandria-book-collection-manager 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +34 -30
- data/.rubocop_todo.yml +139 -54
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Rakefile +10 -11
- data/alexandria-book-collection-manager.gemspec +3 -2
- data/bin/alexandria +1 -1
- data/lib/alexandria.rb +3 -6
- data/lib/alexandria/about.rb +9 -9
- data/lib/alexandria/book_providers.rb +12 -12
- data/lib/alexandria/book_providers/adlibris.rb +14 -18
- data/lib/alexandria/book_providers/amazon_aws.rb +17 -31
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +5 -6
- data/lib/alexandria/book_providers/barnes_and_noble.rb +51 -76
- data/lib/alexandria/book_providers/bol_it.rb +12 -12
- data/lib/alexandria/book_providers/deastore.rb +27 -31
- data/lib/alexandria/book_providers/douban.rb +9 -13
- data/lib/alexandria/book_providers/ibs_it.rb +10 -10
- data/lib/alexandria/book_providers/mcu.rb +12 -18
- data/lib/alexandria/book_providers/proxis.rb +14 -22
- data/lib/alexandria/book_providers/pseudomarc.rb +8 -18
- data/lib/alexandria/book_providers/renaud.rb +16 -16
- data/lib/alexandria/book_providers/siciliano.rb +25 -38
- data/lib/alexandria/book_providers/thalia.rb +13 -16
- data/lib/alexandria/book_providers/webster_it.rb +14 -18
- data/lib/alexandria/book_providers/worldcat.rb +21 -25
- data/lib/alexandria/book_providers/z3950.rb +19 -23
- data/lib/alexandria/config.rb +2 -2
- data/lib/alexandria/execution_queue.rb +3 -1
- data/lib/alexandria/export_library.rb +19 -22
- data/lib/alexandria/import_library.rb +14 -18
- data/lib/alexandria/import_library_csv.rb +12 -30
- data/lib/alexandria/models/book.rb +7 -9
- data/lib/alexandria/models/library.rb +44 -44
- data/lib/alexandria/net.rb +1 -1
- data/lib/alexandria/preferences.rb +12 -57
- data/lib/alexandria/scanners.rb +10 -6
- data/lib/alexandria/scanners/cuecat.rb +2 -2
- data/lib/alexandria/smart_library.rb +12 -12
- data/lib/alexandria/ui.rb +5 -2
- data/lib/alexandria/ui/callbacks.rb +106 -65
- data/lib/alexandria/ui/completion_models.rb +55 -51
- data/lib/alexandria/ui/dialogs/about_dialog.rb +1 -1
- data/lib/alexandria/ui/dialogs/acquire_dialog.rb +25 -51
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +13 -11
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +2 -2
- data/lib/alexandria/ui/dialogs/barcode_animation.rb +39 -23
- data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +16 -21
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +23 -24
- data/lib/alexandria/ui/dialogs/export_dialog.rb +46 -45
- data/lib/alexandria/ui/dialogs/import_dialog.rb +26 -35
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +11 -11
- data/lib/alexandria/ui/dialogs/new_book_dialog.rb +47 -59
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +14 -13
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +12 -11
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +37 -43
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +9 -8
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +47 -53
- data/lib/alexandria/ui/dndable.rb +5 -4
- data/lib/alexandria/ui/icons.rb +19 -19
- data/lib/alexandria/ui/iconview.rb +7 -12
- data/lib/alexandria/ui/iconview_tooltips.rb +22 -109
- data/lib/alexandria/ui/init.rb +7 -15
- data/lib/alexandria/ui/libraries_combo.rb +54 -48
- data/lib/alexandria/ui/listview.rb +30 -85
- data/lib/alexandria/ui/multi_drag_treeview.rb +110 -107
- data/lib/alexandria/ui/sidepane.rb +23 -25
- data/lib/alexandria/ui/sound.rb +18 -27
- data/lib/alexandria/ui/ui_manager.rb +126 -204
- data/lib/alexandria/undo_manager.rb +2 -2
- data/lib/alexandria/version.rb +4 -4
- data/spec/alexandria/book_providers_spec.rb +7 -4
- data/spec/alexandria/library_spec.rb +13 -16
- data/spec/alexandria/scanners/cuecat_spec.rb +1 -2
- data/spec/alexandria/ui/dialogs_spec.rb +5 -1
- data/spec/alexandria/ui/main_app_spec.rb +3 -3
- data/{lib/alexandria/utils.rb → spec/alexandria/ui/sound_spec.rb} +6 -11
- data/spec/alexandria/ui/ui_utilities_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -2
- data/util/rake/fileinstall.rb +17 -33
- data/util/rake/gettextgenerate.rb +2 -4
- data/util/rake/omfgenerate.rb +1 -3
- metadata +23 -11
- data/lib/alexandria/ui/gtk_thread_help.rb +0 -89
@@ -1,6 +1,6 @@
|
|
1
1
|
# Copyright (C) 2005-2006 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
|
3
|
-
# Copyright (C) 2014 Matijs van Zuijlen
|
3
|
+
# Copyright (C) 2014, 2016 Matijs van Zuijlen
|
4
4
|
#
|
5
5
|
# Alexandria is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU General Public License as
|
@@ -47,21 +47,19 @@ module Alexandria
|
|
47
47
|
|
48
48
|
def search(criterion, type)
|
49
49
|
prefs.read
|
50
|
-
criterion = criterion.
|
50
|
+
criterion = criterion.encode(prefs['charset'])
|
51
51
|
|
52
52
|
# We only decode MARC at the moment.
|
53
53
|
# SUTRS needs to be decoded separately, because each Z39.50 server has a
|
54
54
|
# different one.
|
55
|
-
unless marc?
|
56
|
-
raise NoResultsError
|
57
|
-
end
|
55
|
+
raise NoResultsError unless marc?
|
58
56
|
|
59
57
|
isbn = type == SEARCH_BY_ISBN ? criterion : nil
|
60
58
|
criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
|
61
59
|
conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
62
60
|
resultset = search_records(criterion, type, conn_count)
|
63
61
|
log.debug { "total #{resultset.length}" }
|
64
|
-
raise NoResultsError if resultset.
|
62
|
+
raise NoResultsError if resultset.empty?
|
65
63
|
results = books_from_marc(resultset, isbn)
|
66
64
|
type == SEARCH_BY_ISBN ? results.first : results
|
67
65
|
end
|
@@ -80,10 +78,10 @@ module Alexandria
|
|
80
78
|
log.error { ex.backtrace.join("> \n") }
|
81
79
|
begin
|
82
80
|
marc = MARC::Record.new(marc_txt)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
rescue => ex2
|
82
|
+
log.error { ex2.message }
|
83
|
+
log.error { ex2.backtrace.join("> \n") }
|
84
|
+
raise ex2
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -100,14 +98,14 @@ module Alexandria
|
|
100
98
|
|
101
99
|
return if marc.title.nil? # or marc.authors.empty?
|
102
100
|
|
103
|
-
isbn = isbn
|
101
|
+
(isbn = isbn) || marc.isbn
|
104
102
|
isbn = Library.canonicalise_ean(isbn)
|
105
103
|
|
106
104
|
book = Book.new(marc.title, marc.authors,
|
107
105
|
isbn,
|
108
|
-
(marc.publisher
|
106
|
+
(marc.publisher || ''),
|
109
107
|
marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
|
110
|
-
(marc.edition
|
108
|
+
(marc.edition || ''))
|
111
109
|
book
|
112
110
|
end
|
113
111
|
|
@@ -116,7 +114,6 @@ module Alexandria
|
|
116
114
|
resultset[0..9].each do |record|
|
117
115
|
marc_txt = record.render(prefs['charset'], 'UTF-8') # (prefs['record_syntax'], 'USMARC')
|
118
116
|
log.debug { marc_txt }
|
119
|
-
# marc_txt = marc_txt.convert("UTF-8", prefs['charset'])
|
120
117
|
if $DEBUG
|
121
118
|
File.open(',marc.txt', 'wb') do |f| # DEBUG
|
122
119
|
f.write(marc_txt)
|
@@ -151,7 +148,7 @@ module Alexandria
|
|
151
148
|
|
152
149
|
def search_records(criterion, type, conn_count)
|
153
150
|
options = {}
|
154
|
-
unless prefs['username'].empty?
|
151
|
+
unless prefs['username'].empty? || prefs['password'].empty?
|
155
152
|
options['user'] = prefs['username']
|
156
153
|
options['password'] = prefs['password']
|
157
154
|
end
|
@@ -161,7 +158,7 @@ module Alexandria
|
|
161
158
|
conn = ZOOM::Connection.new(options).connect(hostname, port)
|
162
159
|
conn.database_name = prefs['database']
|
163
160
|
|
164
|
-
# HACK turn off piggybacking, just to see CMcG
|
161
|
+
# HACK: turn off piggybacking, just to see CMcG
|
165
162
|
# #conn.piggyback = false
|
166
163
|
|
167
164
|
conn.preferred_record_syntax = prefs['record_syntax']
|
@@ -175,7 +172,7 @@ module Alexandria
|
|
175
172
|
end
|
176
173
|
pqf = ''
|
177
174
|
attr.each { |att| pqf += "@attr 1=#{att} " }
|
178
|
-
pqf += "
|
175
|
+
pqf += '"' + criterion.upcase + '"'
|
179
176
|
log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
|
180
177
|
|
181
178
|
begin
|
@@ -188,7 +185,7 @@ module Alexandria
|
|
188
185
|
conn.search(pqf)
|
189
186
|
rescue => ex
|
190
187
|
if /1005/ =~ ex.message
|
191
|
-
if prefs.variable_named('piggyback')
|
188
|
+
if prefs.variable_named('piggyback') && prefs['piggyback']
|
192
189
|
log.error { "Z39.50 search failed:: #{ex.message}" }
|
193
190
|
log.info { 'Turning off piggybacking for this provider' }
|
194
191
|
prefs.variable_named('piggyback').new_value = false
|
@@ -260,7 +257,7 @@ module Alexandria
|
|
260
257
|
conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
|
261
258
|
resultset = search_records(criterion, type, conn_count)
|
262
259
|
log.debug { "total #{resultset.length}" }
|
263
|
-
raise NoResultsError if resultset.
|
260
|
+
raise NoResultsError if resultset.empty?
|
264
261
|
results = books_from_sutrs(resultset)
|
265
262
|
type == SEARCH_BY_ISBN ? results.first : results
|
266
263
|
end
|
@@ -280,7 +277,6 @@ module Alexandria
|
|
280
277
|
text = record.render(prefs['charset'], 'UTF-8')
|
281
278
|
# File.open(',bl.marc', 'wb') {|f| f.write(text) }
|
282
279
|
log.debug { text }
|
283
|
-
# text = text.convert("UTF-8", prefs['charset'])
|
284
280
|
|
285
281
|
title = isbn = publisher = publish_year = edition = nil
|
286
282
|
authors = []
|
@@ -310,7 +306,7 @@ module Alexandria
|
|
310
306
|
}
|
311
307
|
|
312
308
|
if title # and !authors.empty?
|
313
|
-
book = Book.new(title, authors, isbn, (publisher
|
309
|
+
book = Book.new(title, authors, isbn, (publisher || nil), (publish_year || nil), (edition || nil))
|
314
310
|
results << [book]
|
315
311
|
end
|
316
312
|
end
|
@@ -344,7 +340,7 @@ module Alexandria
|
|
344
340
|
criterion = canonicalise_isbn_with_dashes(criterion)
|
345
341
|
resultset = search_records(criterion, type, 0)
|
346
342
|
log.debug { "total #{resultset.length}" }
|
347
|
-
raise NoResultsError if resultset.
|
343
|
+
raise NoResultsError if resultset.empty?
|
348
344
|
results = books_from_marc(resultset, isbn)
|
349
345
|
type == SEARCH_BY_ISBN ? results.first : results
|
350
346
|
end
|
@@ -371,7 +367,7 @@ module Alexandria
|
|
371
367
|
|
372
368
|
if isbn[0..1] == '88'
|
373
369
|
# Italian speaking area
|
374
|
-
if isbn > '8895000'
|
370
|
+
if isbn > '8895000' && (isbn <= '8899999996')
|
375
371
|
return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
|
376
372
|
elsif isbn > '88900000'
|
377
373
|
return isbn[0..1] + '-' + isbn[2..7] + '-' + isbn[8..8] + '-' + isbn[9..9]
|
data/lib/alexandria/config.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Alexandria
|
2
2
|
module Config
|
3
3
|
SHARE_DIR = File.expand_path('../../share', File.dirname(__FILE__))
|
4
|
-
SOUNDS_DIR = "#{SHARE_DIR}/sounds/alexandria"
|
5
|
-
DATA_DIR = "#{SHARE_DIR}/alexandria"
|
4
|
+
SOUNDS_DIR = "#{SHARE_DIR}/sounds/alexandria".freeze
|
5
|
+
DATA_DIR = "#{SHARE_DIR}/alexandria".freeze
|
6
6
|
MAIN_DATA_DIR = DATA_DIR
|
7
7
|
end
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2007 Cathal Mc Ginley
|
3
|
-
# Copyright (C) 2014 Matijs van Zuijlen
|
3
|
+
# Copyright (C) 2014, 2016 Matijs van Zuijlen
|
4
4
|
#
|
5
5
|
# Alexandria is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU General Public License as
|
@@ -22,7 +22,7 @@
|
|
22
22
|
# iPod Notes support added 20 January 2008 by Tim Malone
|
23
23
|
# require 'cgi'
|
24
24
|
|
25
|
-
begin
|
25
|
+
begin # image_size is optional
|
26
26
|
$IMAGE_SIZE_LOADED = true
|
27
27
|
require 'image_size'
|
28
28
|
rescue LoadError
|
@@ -43,13 +43,10 @@ module Alexandria
|
|
43
43
|
sorted = library.sort_by do |book|
|
44
44
|
book.send(@book_attribute)
|
45
45
|
end
|
46
|
-
unless @ascending
|
47
|
-
sorted.reverse!
|
48
|
-
end
|
46
|
+
sorted.reverse! unless @ascending
|
49
47
|
sorted
|
50
48
|
rescue => ex
|
51
|
-
|
52
|
-
log.warn { "Could not sort library by #{@book_attribute} #{ex.message} #{trace}" }
|
49
|
+
log.warn { "Could not sort library by #{@book_attribute.inspect}: #{ex.message}" }
|
53
50
|
library
|
54
51
|
end
|
55
52
|
|
@@ -174,7 +171,7 @@ module Alexandria
|
|
174
171
|
def export_as_isbn_list(filename)
|
175
172
|
File.open(filename, 'w') do |io|
|
176
173
|
each do |book|
|
177
|
-
io.puts((book.isbn
|
174
|
+
io.puts((book.isbn || ''))
|
178
175
|
end
|
179
176
|
end
|
180
177
|
end
|
@@ -221,7 +218,7 @@ module Alexandria
|
|
221
218
|
end
|
222
219
|
io.puts book.authors.join(', ')
|
223
220
|
io.puts book.edition
|
224
|
-
io.puts((book.isbn
|
221
|
+
io.puts((book.isbn || ''))
|
225
222
|
# we need to close the files so the iPod can be ejected/unmounted without us closing Alexandria
|
226
223
|
io.close
|
227
224
|
end
|
@@ -234,14 +231,14 @@ module Alexandria
|
|
234
231
|
File.open(filename, 'w') do |io|
|
235
232
|
io.puts 'Title' + ';' + 'Authors' + ';' + 'Publisher' + ';' + 'Edition' + ';' + 'ISBN' + ';' + 'Year Published' + ';' + 'Rating' + "(0 to #{UI::MainApp::MAX_RATING_STARS})" + ';' + 'Notes' + ';' + 'Want?' + ';' + 'Read?' + ';' + 'Own?' + ';' + 'Tags'
|
236
233
|
each do |book|
|
237
|
-
io.puts book.title + ';' + book.authors.join(', ') + ';' + (book.publisher
|
234
|
+
io.puts book.title + ';' + book.authors.join(', ') + ';' + (book.publisher || '') + ';' + (book.edition || '') + ';' + (book.isbn || '') + ';' + (book.publishing_year.to_s || '') + ';' + (book.rating.to_s || '0') + ';' + (book.notes || '') + ';' + (book.want ? '1' : '0') + ';' + (book.redd ? '1' : '0') + ';' + (book.own ? '1' : '0') + ';' + (book.tags ? book.tags.join(', ') : '')
|
238
235
|
end
|
239
236
|
end
|
240
237
|
end
|
241
238
|
|
242
239
|
private
|
243
240
|
|
244
|
-
ONIX_DTD_URL = 'http://www.editeur.org/onix/2.1/reference/onix-international.dtd'
|
241
|
+
ONIX_DTD_URL = 'http://www.editeur.org/onix/2.1/reference/onix-international.dtd'.freeze
|
245
242
|
def to_onix_document
|
246
243
|
doc = REXML::Document.new
|
247
244
|
doc << REXML::XMLDecl.new
|
@@ -263,7 +260,7 @@ module Alexandria
|
|
263
260
|
prod.add_element('NotificationType').text = '03' # confirmed
|
264
261
|
prod.add_element('RecordSourceName').text =
|
265
262
|
'Alexandria ' + Alexandria::DISPLAY_VERSION
|
266
|
-
prod.add_element('ISBN').text = (book.isbn
|
263
|
+
prod.add_element('ISBN').text = (book.isbn || '')
|
267
264
|
prod.add_element('ProductForm').text = 'BA' # book
|
268
265
|
prod.add_element('DistinctiveTitle').text = book.title
|
269
266
|
unless book.authors.empty?
|
@@ -274,11 +271,11 @@ module Alexandria
|
|
274
271
|
elem.add_element('PersonName').text = author
|
275
272
|
end
|
276
273
|
end
|
277
|
-
if book.notes
|
274
|
+
if book.notes && !book.notes.empty?
|
278
275
|
elem = prod.add_element('OtherText')
|
279
276
|
# reader description
|
280
277
|
elem.add_element('TextTypeCode').text = '12'
|
281
|
-
elem.add_element('TextFormat').text = '00'
|
278
|
+
elem.add_element('TextFormat').text = '00' # ASCII
|
282
279
|
elem.add_element('Text').text = book.notes
|
283
280
|
end
|
284
281
|
if File.exist?(cover(book))
|
@@ -314,7 +311,7 @@ module Alexandria
|
|
314
311
|
# http://periapsis.org/tellico/doc/hacking.html
|
315
312
|
doc = REXML::Document.new
|
316
313
|
doc << REXML::XMLDecl.new
|
317
|
-
doc << REXML::DocType.new('tellico',
|
314
|
+
doc << REXML::DocType.new('tellico', 'PUBLIC "-//Robby Stephenson/DTD Tellico V7.0//EN" "http://periapsis.org/tellico/dtd/v7/tellico.dtd"')
|
318
315
|
tellico = doc.add_element('tellico')
|
319
316
|
tellico.add_attribute('syntaxVersion', '7')
|
320
317
|
tellico.add_namespace('http://periapsis.org/tellico/')
|
@@ -333,7 +330,7 @@ module Alexandria
|
|
333
330
|
entry.add_attribute('id', new_index)
|
334
331
|
# translate the binding
|
335
332
|
entry.add_element('title').text = book.title
|
336
|
-
entry.add_element('isbn').text = (book.isbn
|
333
|
+
entry.add_element('isbn').text = (book.isbn || '')
|
337
334
|
entry.add_element('pub_year').text = book.publishing_year
|
338
335
|
entry.add_element('binding').text = book.edition
|
339
336
|
entry.add_element('publisher').text = book.publisher
|
@@ -348,7 +345,7 @@ module Alexandria
|
|
348
345
|
unless book.rating == Book::DEFAULT_RATING
|
349
346
|
entry.add_element('rating').text = book.rating
|
350
347
|
end
|
351
|
-
if book.notes
|
348
|
+
if book.notes && !book.notes.empty?
|
352
349
|
entry.add_element('comments').text = book.notes
|
353
350
|
end
|
354
351
|
if File.exist?(cover(book))
|
@@ -434,7 +431,7 @@ EOS
|
|
434
431
|
end
|
435
432
|
|
436
433
|
unless book.authors.empty?
|
437
|
-
xhtml <<
|
434
|
+
xhtml << '<ul class="book_authors">'
|
438
435
|
book.authors.each do |author|
|
439
436
|
xhtml << <<EOS
|
440
437
|
<li class="book_author">#{xhtml_escape(author)}</li>
|
@@ -477,7 +474,7 @@ EOS
|
|
477
474
|
|
478
475
|
auths = Hash.new(0)
|
479
476
|
each do |book|
|
480
|
-
k = (book.authors[0]
|
477
|
+
k = (book.authors[0] || 'Anonymous').split[0]
|
481
478
|
if auths.key?(k)
|
482
479
|
auths[k] += 1
|
483
480
|
else
|
@@ -485,7 +482,7 @@ EOS
|
|
485
482
|
end
|
486
483
|
cite_key = k + auths[k].to_s
|
487
484
|
bibtex << "@BOOK{#{cite_key},\n"
|
488
|
-
bibtex <<
|
485
|
+
bibtex << 'author = "'
|
489
486
|
if book.authors != []
|
490
487
|
bibtex << book.authors[0]
|
491
488
|
book.authors[1..-1].each do |author|
|
@@ -495,11 +492,11 @@ EOS
|
|
495
492
|
bibtex << "\",\n"
|
496
493
|
bibtex << "title = \"#{latex_escape(book.title)}\",\n"
|
497
494
|
bibtex << "publisher = \"#{latex_escape(book.publisher)}\",\n"
|
498
|
-
if book.notes
|
495
|
+
if book.notes && !book.notes.empty?
|
499
496
|
bibtex << "OPTnote = \"#{latex_escape(book.notes)}\",\n"
|
500
497
|
end
|
501
498
|
# year is a required field in bibtex @BOOK
|
502
|
-
bibtex << 'year = ' + (book.publishing_year
|
499
|
+
bibtex << 'year = ' + (book.publishing_year || '"n/a"').to_s + "\n"
|
503
500
|
bibtex << "}\n\n"
|
504
501
|
end
|
505
502
|
bibtex
|
@@ -100,7 +100,7 @@ module Alexandria
|
|
100
100
|
collection = xml.root.elements[1]
|
101
101
|
raise unless collection.name == 'collection'
|
102
102
|
type = collection.attribute('type').value.to_i
|
103
|
-
raise unless type == 2
|
103
|
+
raise unless (type == 2) || (type == 5)
|
104
104
|
|
105
105
|
content = []
|
106
106
|
entries = collection.elements.to_a('entry')
|
@@ -111,19 +111,17 @@ module Alexandria
|
|
111
111
|
keys = ['isbn', 'publisher', 'pub_year', 'binding']
|
112
112
|
|
113
113
|
book_elements = [neaten(elements['title'].text)]
|
114
|
-
if !elements['authors'].nil?
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
book_elements += keys.map {|key|
|
121
|
-
if elements[key]
|
122
|
-
neaten(elements[key].text)
|
123
|
-
end
|
114
|
+
book_elements += if !elements['authors'].nil?
|
115
|
+
[elements['authors'].elements.to_a.map \
|
116
|
+
{ |x| neaten(x.text) }]
|
117
|
+
else
|
118
|
+
[[]]
|
119
|
+
end
|
120
|
+
book_elements += keys.map { |key|
|
121
|
+
neaten(elements[key].text) if elements[key]
|
124
122
|
}
|
125
123
|
# isbn
|
126
|
-
if book_elements[2].nil?
|
124
|
+
if book_elements[2].nil? || book_elements[2].strip.empty?
|
127
125
|
book_elements[2] = nil
|
128
126
|
else
|
129
127
|
begin
|
@@ -138,14 +136,12 @@ module Alexandria
|
|
138
136
|
end
|
139
137
|
book_elements[4] = book_elements[4].to_i unless book_elements[4].nil? # publishing_year
|
140
138
|
puts book_elements.inspect
|
141
|
-
if elements['cover']
|
142
|
-
|
143
|
-
|
144
|
-
cover = nil
|
145
|
-
end
|
139
|
+
cover = if elements['cover']
|
140
|
+
neaten(elements['cover'].text)
|
141
|
+
end
|
146
142
|
puts cover
|
147
143
|
book = Book.new(*book_elements)
|
148
|
-
if elements['rating']
|
144
|
+
if elements['rating'] && (0..UI::MainApp::MAX_RATING_STARS).map.member?(elements['rating'].text.to_i)
|
149
145
|
book.rating = elements['rating'].text.to_i
|
150
146
|
end
|
151
147
|
book.notes = neaten(elements['comments'].text) if elements['comments']
|
@@ -32,9 +32,7 @@ module Alexandria
|
|
32
32
|
|
33
33
|
def index_of(header_name)
|
34
34
|
@header.each_with_index do |h, i|
|
35
|
-
if h == header_name
|
36
|
-
return i
|
37
|
-
end
|
35
|
+
return i if h == header_name
|
38
36
|
end
|
39
37
|
-1
|
40
38
|
end
|
@@ -57,7 +55,7 @@ module Alexandria
|
|
57
55
|
|
58
56
|
# optional extras
|
59
57
|
@notes = index_of('Private Notes')
|
60
|
-
@rating =
|
58
|
+
@rating = index_of('My Rating')
|
61
59
|
@read_count = index_of('Read Count')
|
62
60
|
@date_read = index_of('Date Read')
|
63
61
|
@bookshelves = index_of('Bookshelves') # save names as tags
|
@@ -72,10 +70,8 @@ module Alexandria
|
|
72
70
|
additional.split(',').each do |add|
|
73
71
|
authors << normalize(add)
|
74
72
|
end
|
75
|
-
isbn = row[@isbn] # TODO canonicalize_ean...
|
76
|
-
if isbn
|
77
|
-
isbn = Library.canonicalise_ean(isbn)
|
78
|
-
end
|
73
|
+
isbn = row[@isbn] # TODO: canonicalize_ean...
|
74
|
+
isbn = Library.canonicalise_ean(isbn) if isbn
|
79
75
|
publisher = normalize(row[@publisher])
|
80
76
|
year = row[@publishing_year].to_i
|
81
77
|
edition = normalize(row[@edition])
|
@@ -85,17 +81,11 @@ module Alexandria
|
|
85
81
|
publisher,
|
86
82
|
year,
|
87
83
|
edition)
|
88
|
-
if row[@notes]
|
89
|
-
|
90
|
-
end
|
91
|
-
if row[@rating]
|
92
|
-
book.rating = row[@rating].to_i
|
93
|
-
end
|
84
|
+
book.notes = normalize(row[@notes]) if row[@notes]
|
85
|
+
book.rating = row[@rating].to_i if row[@rating]
|
94
86
|
if row[@read_count]
|
95
87
|
count = row[@read_count].to_i
|
96
|
-
if count > 0
|
97
|
-
book.redd = true
|
98
|
-
end
|
88
|
+
book.redd = true if count > 0
|
99
89
|
end
|
100
90
|
if row[@date_read]
|
101
91
|
begin
|
@@ -120,10 +110,8 @@ module Alexandria
|
|
120
110
|
if row[@bookshelves]
|
121
111
|
shelves = normalize(row[@bookshelves]).split
|
122
112
|
shelves.each do |shelf|
|
123
|
-
tag = shelf.
|
124
|
-
unless book.tags.include? tag
|
125
|
-
book.tags << tag
|
126
|
-
end
|
113
|
+
tag = shelf.tr('-', ' ')
|
114
|
+
book.tags << tag unless book.tags.include? tag
|
127
115
|
end
|
128
116
|
end
|
129
117
|
puts "Goodreads loading #{book.title}" if $DEBUG
|
@@ -179,19 +167,13 @@ module Alexandria
|
|
179
167
|
publisher,
|
180
168
|
year,
|
181
169
|
edition)
|
182
|
-
if row[@notes]
|
183
|
-
book.notes = normalize(row[@notes])
|
184
|
-
end
|
170
|
+
book.notes = normalize(row[@notes]) if row[@notes]
|
185
171
|
|
186
|
-
if row[@rating]
|
187
|
-
book.rating = row[@rating].to_i
|
188
|
-
end
|
172
|
+
book.rating = row[@rating].to_i if row[@rating]
|
189
173
|
if row[@tags]
|
190
174
|
tags = normalize(row[@tags]).split(',')
|
191
175
|
tags.each do |tag|
|
192
|
-
unless book.tags.include? tag
|
193
|
-
book.tags << tag
|
194
|
-
end
|
176
|
+
book.tags << tag unless book.tags.include? tag
|
195
177
|
end
|
196
178
|
end
|
197
179
|
|