alexandria-book-collection-manager 0.7.2 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ruby.yml +77 -0
  4. data/.gitignore +5 -1
  5. data/.hound.yml +2 -0
  6. data/.rubocop.yml +87 -37
  7. data/.rubocop_todo.yml +62 -191
  8. data/.simplecov +5 -2
  9. data/CHANGELOG.md +63 -0
  10. data/Gemfile +4 -3
  11. data/INSTALL.md +26 -14
  12. data/README.md +52 -42
  13. data/Rakefile +93 -109
  14. data/TODO.md +9 -1
  15. data/alexandria-book-collection-manager.gemspec +50 -43
  16. data/bin/alexandria +30 -53
  17. data/doc/FAQ +2 -6
  18. data/doc/dependency_decisions.yml +27 -8
  19. data/lib/alexandria.rb +27 -37
  20. data/lib/alexandria/about.rb +50 -50
  21. data/lib/alexandria/book_providers.rb +90 -97
  22. data/lib/alexandria/book_providers/adlibris.rb +41 -76
  23. data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
  24. data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
  25. data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
  26. data/lib/alexandria/book_providers/douban.rb +26 -42
  27. data/lib/alexandria/book_providers/proxis.rb +44 -55
  28. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  29. data/lib/alexandria/book_providers/siciliano.rb +64 -65
  30. data/lib/alexandria/book_providers/thalia.rb +42 -41
  31. data/lib/alexandria/book_providers/web.rb +15 -33
  32. data/lib/alexandria/book_providers/worldcat.rb +70 -97
  33. data/lib/alexandria/book_providers/z3950.rb +160 -173
  34. data/lib/alexandria/config.rb +1 -1
  35. data/lib/alexandria/console.rb +8 -21
  36. data/lib/alexandria/default_preferences.rb +37 -0
  37. data/lib/alexandria/execution_queue.rb +15 -13
  38. data/lib/alexandria/export_format.rb +47 -0
  39. data/lib/alexandria/export_library.rb +193 -300
  40. data/lib/alexandria/import_library.rb +108 -141
  41. data/lib/alexandria/import_library_csv.rb +43 -46
  42. data/lib/alexandria/library_collection.rb +79 -0
  43. data/lib/alexandria/library_sort_order.rb +45 -0
  44. data/lib/alexandria/library_store.rb +233 -0
  45. data/lib/alexandria/logging.rb +11 -13
  46. data/lib/alexandria/models/book.rb +13 -20
  47. data/lib/alexandria/models/library.rb +81 -353
  48. data/lib/alexandria/net.rb +5 -6
  49. data/lib/alexandria/preferences.rb +73 -87
  50. data/lib/alexandria/scanners.rb +2 -2
  51. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
  52. data/lib/alexandria/scanners/keyboard.rb +8 -8
  53. data/lib/alexandria/smart_library.rb +133 -170
  54. data/lib/alexandria/ui.rb +15 -15
  55. data/lib/alexandria/ui/about_dialog.rb +49 -0
  56. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
  57. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  58. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  59. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  60. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
  61. data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
  62. data/lib/alexandria/ui/builder_base.rb +7 -27
  63. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  64. data/lib/alexandria/ui/callbacks.rb +189 -183
  65. data/lib/alexandria/ui/completion_models.rb +10 -23
  66. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  67. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  68. data/lib/alexandria/ui/dndable.rb +7 -7
  69. data/lib/alexandria/ui/error_dialog.rb +25 -0
  70. data/lib/alexandria/ui/export_dialog.rb +142 -0
  71. data/lib/alexandria/ui/icons.rb +47 -63
  72. data/lib/alexandria/ui/iconview.rb +12 -10
  73. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  74. data/lib/alexandria/ui/import_dialog.rb +157 -0
  75. data/lib/alexandria/ui/init.rb +21 -33
  76. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  77. data/lib/alexandria/ui/libraries_combo.rb +16 -14
  78. data/lib/alexandria/ui/listview.rb +73 -87
  79. data/lib/alexandria/ui/main_app.rb +24 -26
  80. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  81. data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
  82. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
  83. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  84. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  85. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  86. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  87. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  88. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  89. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  90. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
  91. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  92. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  93. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  94. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  95. data/lib/alexandria/ui/sound.rb +11 -13
  96. data/lib/alexandria/ui/ui_manager.rb +236 -251
  97. data/lib/alexandria/undo_manager.rb +1 -0
  98. data/lib/alexandria/version.rb +4 -19
  99. data/lib/alexandria/web_themes.rb +22 -21
  100. data/po/Makefile +2 -2
  101. data/po/cs.po +993 -880
  102. data/po/cy.po +957 -874
  103. data/po/de.po +990 -869
  104. data/po/el.po +989 -869
  105. data/po/es.po +985 -865
  106. data/po/fr.po +986 -870
  107. data/po/ga.po +907 -823
  108. data/po/gl.po +981 -865
  109. data/po/it.po +986 -868
  110. data/po/ja.po +969 -853
  111. data/po/mk.po +983 -863
  112. data/po/nb.po +979 -863
  113. data/po/nl.po +983 -864
  114. data/po/pl.po +1017 -974
  115. data/po/pt.po +988 -861
  116. data/po/pt_BR.po +984 -868
  117. data/po/ru.po +992 -873
  118. data/po/sk.po +987 -869
  119. data/po/sv.po +977 -861
  120. data/po/uk.po +975 -865
  121. data/po/zh_TW.po +976 -860
  122. data/schemas/alexandria.schemas +25 -3
  123. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  124. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  125. data/share/alexandria/glade/main_app__builder.glade +24 -33
  126. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  127. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  128. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  129. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  130. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  131. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  132. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  133. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  134. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  135. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  136. data/spec/alexandria/book_providers_spec.rb +75 -171
  137. data/spec/alexandria/book_spec.rb +12 -10
  138. data/spec/alexandria/console_spec.rb +27 -0
  139. data/spec/alexandria/export_library_spec.rb +130 -0
  140. data/spec/alexandria/library_spec.rb +128 -172
  141. data/spec/alexandria/library_store_spec.rb +37 -0
  142. data/spec/alexandria/preferences_spec.rb +44 -17
  143. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  144. data/spec/alexandria/smart_library_spec.rb +30 -25
  145. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  146. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  148. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  150. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  152. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  153. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  154. data/spec/alexandria/ui/icons_spec.rb +26 -0
  155. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  156. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  157. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  159. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  160. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  161. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  162. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  163. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  164. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  165. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  166. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  167. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  168. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  169. data/spec/alexandria/ui/sound_spec.rb +2 -2
  170. data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
  171. data/spec/end_to_end/basic_run_spec.rb +52 -0
  172. data/spec/spec_helper.rb +65 -33
  173. data/tasks/setup.rb +2 -2
  174. data/tasks/spec.rake +16 -3
  175. data/util/rake/fileinstall.rb +39 -35
  176. data/util/rake/gettextgenerate.rb +7 -7
  177. data/util/rake/omfgenerate.rb +7 -7
  178. metadata +178 -45
  179. data/dogtail/basic_run_test.py +0 -9
  180. data/lib/alexandria/book_providers/deastore.rb +0 -265
  181. data/lib/alexandria/book_providers/mcu.rb +0 -182
  182. data/lib/alexandria/book_providers/renaud.rb +0 -149
  183. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
  184. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
  185. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
  186. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
  187. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  188. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  189. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
  190. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  191. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  192. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
  193. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
  194. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
  195. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  196. data/spec/alexandria/ui/dialogs_spec.rb +0 -96
  197. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  198. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  199. data/spec/alexandria/utilities_spec.rb +0 -52
  200. data/tasks/dogtail.rake +0 -6
@@ -19,8 +19,8 @@
19
19
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
20
20
  # Fifth Floor, Boston, MA 02110-1301 USA.
21
21
 
22
- require 'singleton'
23
- require 'observer'
22
+ require "singleton"
23
+ require "observer"
24
24
 
25
25
  module Alexandria
26
26
  # FIXME: Use delegation instead of inheritance.
@@ -29,27 +29,28 @@ module Alexandria
29
29
  include Singleton
30
30
  include Observable
31
31
  include GetText
32
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
32
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
33
33
 
34
34
  SEARCH_BY_ISBN, SEARCH_BY_TITLE, SEARCH_BY_AUTHORS,
35
35
  SEARCH_BY_KEYWORD = (0..3).to_a
36
36
 
37
37
  class SearchError < StandardError; end
38
38
  class NoResultsError < SearchError; end
39
- class ProviderSkippedError < NoResultsError; end # not an error :^(
40
- class SearchEmptyError < SearchError; end # sigh, again not really an error
41
39
  class TooManyResultsError < SearchError; end
42
40
  class InvalidSearchTypeError < SearchError; end
43
41
 
42
+ # These errors are not really errors
43
+ class ProviderSkippedError < NoResultsError; end
44
+ class SearchEmptyError < SearchError; end
45
+
44
46
  def self.search(criterion, type)
45
47
  factory_n = 0
46
- # puts "book_providers search #{self.instance.count_observers}"
47
48
 
48
49
  begin
49
50
  factory = instance[factory_n]
50
- puts factory.fullname + ' lookup' if $DEBUG
51
+ log.debug { factory.fullname + " lookup" }
51
52
  unless factory.enabled
52
- puts factory.fullname + ' disabled!, skipping...' if $DEBUG
53
+ log.debug { factory.fullname + " disabled!, skipping..." }
53
54
  raise ProviderSkippedError
54
55
  end
55
56
  instance.changed
@@ -64,14 +65,14 @@ module Alexandria
64
65
  instance.notify_observers(:not_found, factory.fullname) # new
65
66
  raise NoResultsError
66
67
  else
67
- log.info { 'found at ' + factory.fullname }
68
+ log.info { "found at " + factory.fullname }
68
69
  instance.changed
69
70
  instance.notify_observers(:found, factory.fullname) # new
70
- return results
71
+ results
71
72
  end
72
- rescue => boom
73
- if boom.is_a? NoResultsError
74
- unless boom.instance_of? ProviderSkippedError
73
+ rescue StandardError => ex
74
+ if ex.is_a? NoResultsError
75
+ unless ex.instance_of? ProviderSkippedError
75
76
  instance.changed
76
77
  instance.notify_observers(:not_found, factory.fullname) # new
77
78
  Thread.new { sleep(0.5) }.join
@@ -80,41 +81,41 @@ module Alexandria
80
81
  instance.changed
81
82
  instance.notify_observers(:error, factory.fullname) # new
82
83
  Thread.new { sleep(0.5) }.join # hrmmmm, to make readable...
83
- trace = boom.backtrace.join("\n >")
84
- log.warn { "Provider #{factory.name} encountered error: #{boom.message} #{trace}" }
84
+ trace = ex.backtrace.join("\n >")
85
+ log.warn { "Provider #{factory.name} encountered error: #{ex.message} #{trace}" }
85
86
  end
86
- if last == factory
87
+ if factory == instance.last
87
88
  log.warn { "Error while searching #{criterion}" }
88
- message = case boom
89
+ message = case ex
89
90
  when Timeout::Error
90
91
  _("Couldn't reach the provider '%s': timeout " \
91
- 'expired.') % factory.name
92
+ "expired.") % factory.name
92
93
 
93
94
  when SocketError
94
95
  format(_("Couldn't reach the provider '%s': socket " \
95
- 'error (%s).'), factory.name, boom.message)
96
+ "error (%s)."), factory.name, ex.message)
96
97
 
97
98
  when NoResultsError
98
- _('No results were found. Make sure your ' \
99
- 'search criterion is spelled correctly, and ' \
100
- 'try again.')
99
+ _("No results were found. Make sure your " \
100
+ "search criterion is spelled correctly, and " \
101
+ "try again.")
101
102
 
102
103
  when ProviderSkippedError
103
- _('No results were found. Make sure your ' \
104
- 'search criterion is spelled correctly, and ' \
105
- 'try again.')
104
+ _("No results were found. Make sure your " \
105
+ "search criterion is spelled correctly, and " \
106
+ "try again.")
106
107
 
107
108
  when TooManyResultsError
108
- _('Too many results for that search.')
109
+ _("Too many results for that search.")
109
110
 
110
111
  when InvalidSearchTypeError
111
- _('Invalid search type.')
112
+ _("Invalid search type.")
112
113
 
113
114
  else
114
- boom.message
115
+ ex.message
115
116
  end
116
- puts "raising empty error #{message}"
117
- raise SearchEmptyError, message
117
+ log.debug { "raising empty error #{message}" }
118
+ raise SearchEmptyError, message # rubocop:disable GetText/DecorateFunctionMessage
118
119
  else
119
120
  factory_n += 1
120
121
  retry
@@ -152,9 +153,8 @@ module Alexandria
152
153
  end
153
154
 
154
155
  def new_value=(new_value)
155
- message = @provider.variable_name(self) + '='
156
- Alexandria::Preferences.instance.send(message,
157
- new_value)
156
+ name = @provider.variable_name(self)
157
+ Alexandria::Preferences.instance.set_variable(name, new_value)
158
158
  self.value = new_value
159
159
  end
160
160
 
@@ -187,9 +187,9 @@ module Alexandria
187
187
 
188
188
  def read
189
189
  each do |var|
190
- message = @provider.variable_name(var)
191
- val = Alexandria::Preferences.instance.send(message)
192
- var.value = val unless val.nil? || ((val == '') && var.mandatory?)
190
+ name = @provider.variable_name(var)
191
+ val = Alexandria::Preferences.instance.get_variable(name)
192
+ var.value = val unless val.nil? || ((val == "") && var.mandatory?)
193
193
  end
194
194
  end
195
195
  end
@@ -203,35 +203,35 @@ module Alexandria
203
203
  @name = name
204
204
  @fullname = (fullname || name)
205
205
  @prefs = Preferences.new(self)
206
- @prefs.add('enabled', _('Enabled'), true, [true, false])
206
+ @prefs.add("enabled", _("Enabled"), true, [true, false])
207
207
  end
208
208
 
209
209
  def enabled
210
- @prefs['enabled']
210
+ @prefs["enabled"]
211
211
  end
212
212
 
213
213
  def toggle_enabled
214
214
  old_value = enabled
215
- @prefs.variable_named('enabled').new_value = !old_value
215
+ @prefs.variable_named("enabled").new_value = !old_value
216
216
  end
217
217
 
218
218
  def reinitialize(fullname)
219
- @name << '_' << fullname.hash.to_s
219
+ @name = "#{name}_#{fullname.hash}"
220
220
  @fullname = fullname
221
221
  prefs = Alexandria::Preferences.instance
222
- ary = prefs.abstract_providers
222
+ ary = prefs.get_variable :abstract_providers
223
223
  ary ||= []
224
224
  ary << @name
225
- prefs.abstract_providers = ary
226
- message = variable_name('name') + '='
227
- prefs.send(message, @fullname)
225
+ prefs.set_variable :abstract_providers, ary
226
+ message = variable_name("name")
227
+ prefs.set_variable(message, @fullname)
228
228
  end
229
229
 
230
230
  def remove
231
231
  prefs = Alexandria::Preferences.instance
232
- if (ary = prefs.abstract_providers)
232
+ if (ary = prefs.get_variable :abstract_providers)
233
233
  ary.delete(@name)
234
- prefs.abstract_providers = ary
234
+ prefs.set_variable :abstract_providers, ary
235
235
  end
236
236
  if (ary = prefs.providers_priority) && ary.include?(@name)
237
237
  ary.delete(@name)
@@ -241,7 +241,7 @@ module Alexandria
241
241
  name = variable_name(variable)
242
242
  prefs.remove_preference(name)
243
243
  end
244
- name = variable_name('name')
244
+ name = variable_name("name")
245
245
  prefs.remove_preference(name)
246
246
  prefs.save!
247
247
  end
@@ -255,7 +255,7 @@ module Alexandria
255
255
  else
256
256
  raise
257
257
  end
258
- @name.downcase + '_' + s
258
+ @name.downcase + "_" + s
259
259
  end
260
260
 
261
261
  def transport
@@ -271,8 +271,8 @@ module Alexandria
271
271
  !included_modules.include?(Singleton)
272
272
  end
273
273
 
274
- def <=>(provider)
275
- fullname <=> provider.fullname
274
+ def <=>(other)
275
+ fullname <=> other.fullname
276
276
  end
277
277
 
278
278
  # FIXME: Clean up this complex abstract/concrete class system
@@ -289,26 +289,21 @@ module Alexandria
289
289
  unabstract
290
290
  end
291
291
 
292
- require 'alexandria/book_providers/mcu' # yep, still mostly works !
293
- require 'alexandria/book_providers/douban' # only requires YAML
294
-
295
- # require 'alexandria/book_providers/renaud'
296
- log.info { 'Not loading Renaud (provider not functional)' }
292
+ require "alexandria/book_providers/douban" # only requires YAML
297
293
 
298
294
  # Amazon AWS (Amazon Associates Web Services) provider, needs hpricot
299
- require 'alexandria/book_providers/amazon_aws'
295
+ require "alexandria/book_providers/amazon_aws"
300
296
 
301
297
  # Website based providers
302
- require 'alexandria/book_providers/adlibris'
303
- require 'alexandria/book_providers/barnes_and_noble'
304
- require 'alexandria/book_providers/deastore'
305
- require 'alexandria/book_providers/proxis'
306
- require 'alexandria/book_providers/siciliano'
307
- require 'alexandria/book_providers/thalia'
308
- require 'alexandria/book_providers/worldcat'
298
+ require "alexandria/book_providers/adlibris"
299
+ require "alexandria/book_providers/barnes_and_noble"
300
+ require "alexandria/book_providers/proxis"
301
+ require "alexandria/book_providers/siciliano"
302
+ require "alexandria/book_providers/thalia"
303
+ require "alexandria/book_providers/worldcat"
309
304
 
310
305
  # Z39.50 based providers
311
- require 'alexandria/book_providers/z3950'
306
+ require "alexandria/book_providers/z3950"
312
307
 
313
308
  attr_reader :abstract_classes
314
309
 
@@ -328,11 +323,11 @@ module Alexandria
328
323
  self.class.constants.each do |constant|
329
324
  md = /(.+)Provider$/.match(constant)
330
325
  next unless md
326
+
331
327
  klass = self.class.module_eval(constant.to_s)
332
- if klass.ancestors.include?(AbstractProvider) &&
328
+ if klass < AbstractProvider &&
333
329
  (klass != GenericProvider) &&
334
- (klass != WebsiteBasedProvider) &&
335
- (klass != AbstractProvider)
330
+ (klass != WebsiteBasedProvider)
336
331
 
337
332
  if klass.abstract?
338
333
  @abstract_classes << klass
@@ -341,15 +336,18 @@ module Alexandria
341
336
  end
342
337
  end
343
338
  end
344
- if (ary = @prefs.abstract_providers)
339
+ if (ary = @prefs.get_variable :abstract_providers)
345
340
  ary.each do |name|
346
341
  md = /^(.+)_/.match(name)
347
342
  next unless md
348
- klass_name = md[1] + 'Provider'
343
+
344
+ klass_name = md[1] + "Provider"
349
345
  klass = @abstract_classes.find { |x| x.name.include?(klass_name) }
350
346
  next unless klass
351
- fullname = @prefs.send(name.downcase + '_name')
347
+
348
+ fullname = @prefs.send(name.downcase + "_name")
352
349
  next unless fullname
350
+
353
351
  instance = klass.new
354
352
  instance.name = name
355
353
  instance.fullname = fullname
@@ -367,41 +365,36 @@ module Alexandria
367
365
  compact!
368
366
  end
369
367
 
370
- # FIXME: Define the handful of methods that use this.
371
- def self.method_missing(id, *args, &block)
372
- if instance.respond_to? id
373
- instance.method(id).call(*args, &block)
374
- else
375
- super
376
- end
368
+ def self.list
369
+ instance
370
+ end
371
+
372
+ def self.abstract_classes
373
+ instance.abstract_classes
377
374
  end
378
375
 
379
376
  private
380
377
 
381
378
  def rejig_providers_priority
382
379
  priority = (@prefs.providers_priority || [])
383
- unless priority.empty?
384
- changed = false
380
+ return if priority.empty?
385
381
 
386
- if (ecs_index = priority.index('AmazonECS'))
387
- priority[ecs_index] = 'Amazon' # replace legacy "AmazonECS" name
388
- priority.uniq! # remove any other "Amazon" from the list
389
- changed = true
390
- end
391
- if (deastore_index = priority.index('DeaStore_it'))
392
- priority[deastore_index] = 'DeaStore'
393
- changed = true
394
- end
395
- if (worldcat_index = priority.index('Worldcat'))
396
- priority[worldcat_index] = 'WorldCat'
397
- changed = true
398
- end
399
- if (adlibris_index = priority.index('Adlibris'))
400
- priority[adlibris_index] = 'AdLibris'
401
- changed = true
402
- end
403
- @prefs.providers_priority = priority if changed
382
+ changed = false
383
+
384
+ if (ecs_index = priority.index("AmazonECS"))
385
+ priority[ecs_index] = "Amazon" # replace legacy "AmazonECS" name
386
+ priority.uniq! # remove any other "Amazon" from the list
387
+ changed = true
388
+ end
389
+ if (worldcat_index = priority.index("Worldcat"))
390
+ priority[worldcat_index] = "WorldCat"
391
+ changed = true
392
+ end
393
+ if (adlibris_index = priority.index("Adlibris"))
394
+ priority[adlibris_index] = "AdLibris"
395
+ changed = true
404
396
  end
397
+ @prefs.providers_priority = priority if changed
405
398
  end
406
399
  end
407
400
  end
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby -*-
3
+ # This file is part of Alexandria.
4
4
  #
5
- # Copyright (C) 2009 Cathal Mc Ginley
6
- # Copyright (C) 2014 Matijs van Zuijlen
7
- #
8
- # Alexandria is free software; you can redistribute it and/or
9
- # modify it under the terms of the GNU General Public License as
10
- # published by the Free Software Foundation; either version 2 of the
11
- # License, or (at your option) any later version.
12
- #
13
- # Alexandria is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- # General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public
19
- # License along with Alexandria; see the file COPYING. If not,
20
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
21
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
22
6
 
23
7
  # AdLibris Bokhandel AB http://www.adlibris.com/se/
24
8
  # Swedish online book store
@@ -27,23 +11,23 @@
27
11
  # modified to fit the structure of Alexandria book providers.
28
12
  # (26 Feb 2009)
29
13
 
30
- require 'cgi'
31
- require 'alexandria/book_providers/web'
14
+ require "cgi"
15
+ require "alexandria/book_providers/web"
32
16
 
33
17
  module Alexandria
34
18
  class BookProviders
35
19
  class AdLibrisProvider < WebsiteBasedProvider
36
- include Alexandria::Logging
20
+ include Logging
37
21
 
38
- SITE = 'http://www.adlibris.com/se/'
22
+ SITE = "http://www.adlibris.com/se/"
39
23
 
40
24
  BASE_SEARCH_URL = "#{SITE}searchresult.aspx?search=advanced&%s=%s" \
41
- '&fromproduct=False' # type/term
25
+ "&fromproduct=False" # type/term
42
26
 
43
27
  PRODUCT_URL = "#{SITE}product.aspx?isbn=%s"
44
28
 
45
29
  def initialize
46
- super('AdLibris', 'AdLibris (Sweden)')
30
+ super("AdLibris", "AdLibris (Sweden)")
47
31
  prefs.read
48
32
  # @ent = HTMLEntities.new
49
33
  end
@@ -67,7 +51,7 @@ module Alexandria
67
51
  ## url
68
52
  def url(book)
69
53
  create_search_uri(SEARCH_BY_ISBN, book.isbn)
70
- rescue => ex
54
+ rescue StandardError => ex
71
55
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
72
56
  nil
73
57
  end
@@ -79,10 +63,10 @@ module Alexandria
79
63
  PRODUCT_URL % Library.canonicalise_isbn(search_term)
80
64
  else
81
65
  (search_type_code = {
82
- SEARCH_BY_AUTHORS => 'author',
83
- SEARCH_BY_TITLE => 'title',
84
- SEARCH_BY_KEYWORD => 'keyword'
85
- }[search_type]) || 'keyword'
66
+ SEARCH_BY_AUTHORS => "author",
67
+ SEARCH_BY_TITLE => "title",
68
+ SEARCH_BY_KEYWORD => "keyword"
69
+ }[search_type]) || "keyword"
86
70
  search_term_encoded = CGI.escape(search_term)
87
71
  format(BASE_SEARCH_URL, search_type_code, search_term_encoded)
88
72
  end
@@ -97,20 +81,17 @@ module Alexandria
97
81
  end
98
82
 
99
83
  def parse_search_result_data(html)
100
- # adlibris site presents data in ISO-8859-1, so change it to UTF-8
101
- # html = Iconv.conv("UTF-8", "ISO-8859-1", html)
102
- # doc = Hpricot(html)
103
84
  doc = html_to_doc(html)
104
85
  book_search_results = []
105
86
 
106
87
  search_hit = doc.search("div'searchResult")[0]
107
88
  return [] unless search_hit
108
89
 
109
- (search_hit / 'ul.ulSearch table').each do |t|
90
+ (search_hit / "ul.ulSearch table").each do |t|
110
91
  result = {}
111
- if (title_data = (t % 'div.divTitle'))
92
+ if (title_data = (t % "div.divTitle"))
112
93
  result[:title] = (title_data % :a).inner_text
113
- lookup_url = (title_data % :a)['href']
94
+ lookup_url = (title_data % :a)["href"]
114
95
  end
115
96
  result[:lookup_url] = "#{SITE}#{lookup_url}"
116
97
 
@@ -119,45 +100,25 @@ module Alexandria
119
100
  book_search_results
120
101
  end
121
102
 
122
- # def binding_type(binding) # swedish string
123
- # # hrm, this is a HACK and not currently working
124
- # # perhaps use regexes instead...
125
- # {"inbunden" => :hardback,
126
- # "pocket" => :paperback,
127
- # "storpocket" => :paperback,
128
- # "kartonnage" => :hardback,
129
- # "kassettbok" => :audiobook}[binding.downcase] or :paperback
130
- # # H&#228;ftad == Paperback
131
- # end
132
-
133
103
  def normalize(text)
134
- # unless text.nil?
135
- # text = @ent.decode(text).strip
136
- # end
137
104
  text
138
105
  end
139
106
 
140
107
  def parse_result_data(html)
141
- # adlibris site presents data in ISO-8859-1, so change it to UTF-8
142
- # html = Iconv.conv("UTF-8", "ISO-8859-1", html)
143
- ## File.open(',log.html', 'wb') {|f| f.write('<?xml encoding="utf-8"?>'); f.write(html) } # DEBUG
144
- # doc = Hpricot(html)
145
108
  doc = html_to_doc(html)
146
109
  begin
147
- title = nil
148
- if (h1 = doc.at('div.productTitleFormat h1'))
149
- title = text_of(h1)
150
- else
151
- raise NoResultsError, 'title not found on page'
152
- end
110
+ h1 = doc.at("div.productTitleFormat h1")
111
+ raise NoResultsError, _("title not found on page") unless h1
153
112
 
154
- product = doc.at('div.product')
155
- ul_info = doc.at('ul.info') # NOTE, two of these
113
+ title = text_of(h1)
156
114
 
157
- author_cells = ul_info.search('li.liAuthor') # css-like search
115
+ product = doc.at("div.product")
116
+ ul_info = doc.at("ul.info") # NOTE, two of these
117
+
118
+ author_cells = ul_info.search("li.liAuthor") # css-like search
158
119
  authors = []
159
120
  author_cells.each do |li|
160
- author_name = text_of(li.search('h2 > a')[0])
121
+ author_name = text_of(li.search("h2 > a")[0])
161
122
 
162
123
  authors << author_name
163
124
  end
@@ -168,9 +129,9 @@ module Alexandria
168
129
  end
169
130
 
170
131
  binding = nil
171
- if (format = doc.search('div.productTitleFormat span').first)
132
+ if (format = doc.search("div.productTitleFormat span").first)
172
133
  binding = text_of(format)
173
- binding = Regexp.last_match[1] if binding =~ /\(([^\)]+)\)/
134
+ binding = Regexp.last_match[1] if binding =~ /\(([^)]+)\)/
174
135
  end
175
136
 
176
137
  year = nil
@@ -185,8 +146,9 @@ module Alexandria
185
146
  isbn_tds.each do |isbn_td|
186
147
  isbn = isbn_td.inner_text
187
148
  next unless isbn =~ /[0-9x]{10,13}/i
188
- isbn.gsub(/(\n|\r)/, ' ')
189
- isbn = Regexp.last_match[1] if isbn =~ /:[\s]*([0-9x]+)/i
149
+
150
+ isbn.gsub(/(\n|\r)/, " ")
151
+ isbn = Regexp.last_match[1] if isbn =~ /:\s*([0-9x]+)/i
190
152
  isbns << isbn
191
153
  end
192
154
  isbn = isbns.first
@@ -194,13 +156,15 @@ module Alexandria
194
156
 
195
157
  # cover
196
158
  image_url = nil
197
- if (cover_img = doc.search('span.imageWithShadow img[@id$="ProductImageNotLinked"]').first)
198
- image_url = if cover_img['src'] =~ /^http\:\/\//
199
- cover_img['src']
159
+ cover_img =
160
+ doc.search('span.imageWithShadow img[@id$="ProductImageNotLinked"]').first
161
+ if cover_img
162
+ image_url = if cover_img["src"].start_with?("http://")
163
+ cover_img["src"]
200
164
  else
201
165
  "#{SITE}/#{cover_img['src']}" # HACK: use html base
202
166
  end
203
- if image_url =~ /noimage.gif$/
167
+ if /noimage.gif$/.match?(image_url)
204
168
  # no point downloading a "no image" graphic
205
169
  # Alexandria has its own generic book icon...
206
170
  image_url = nil
@@ -210,14 +174,15 @@ module Alexandria
210
174
 
211
175
  book = Book.new(title, authors, isbn, publisher, year, binding)
212
176
 
213
- return [book, image_url]
214
- rescue => ex
177
+ [book, image_url]
178
+ rescue StandardError => ex
215
179
  raise ex if ex.instance_of? NoResultsError
180
+
216
181
  trace = ex.backtrace.join("\n> ")
217
- log.warn {
218
- 'Failed parsing search results for AdLibris ' \
182
+ log.warn do
183
+ "Failed parsing search results for AdLibris " \
219
184
  "#{ex.message} #{trace}"
220
- }
185
+ end
221
186
  raise NoResultsError
222
187
  end
223
188
  end