alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,66 +1,51 @@
1
- # Copyright (C) 2005-2006 Laurent Sansonetti
2
- # Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
3
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
4
- #
5
- # Alexandria is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License as
7
- # published by the Free Software Foundation; either version 2 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # Alexandria is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # General Public License for more details.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
14
4
  #
15
- # You should have received a copy of the GNU General Public
16
- # License along with Alexandria; see the file COPYING. If not,
17
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
18
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
19
6
 
20
7
  ## $Z3950_DEBUG = $DEBUG
21
8
 
22
- require 'zoom'
23
- require 'alexandria/book_providers/pseudomarc'
24
- require 'marc'
9
+ require "zoom"
10
+ require "alexandria/book_providers/pseudomarc"
11
+ require "marc"
25
12
 
26
13
  module Alexandria
27
14
  class BookProviders
28
15
  class Z3950Provider < AbstractProvider
29
16
  include Logging
30
17
  include GetText
31
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
18
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
32
19
 
33
- def initialize(name = 'Z3950', fullname = 'Z39.50')
20
+ def initialize(name = "Z3950", fullname = "Z39.50")
34
21
  super
35
- prefs.add('hostname', _('Hostname'), '')
36
- prefs.add('port', _('Port'), 7090)
37
- prefs.add('database', _('Database'), '')
38
- prefs.add('record_syntax', _('Record syntax'), 'USMARC', ['USMARC', 'UNIMARC', 'SUTRS'])
39
- prefs.add('username', _('Username'), '', nil, false)
40
- prefs.add('password', _('Password'), '', nil, false)
41
- prefs.add('charset', _('Charset encoding'), 'ISO-8859-1')
22
+ prefs.add("hostname", _("Hostname"), "")
23
+ prefs.add("port", _("Port"), 7090)
24
+ prefs.add("database", _("Database"), "")
25
+ prefs.add("record_syntax", _("Record syntax"), "USMARC",
26
+ ["USMARC", "UNIMARC", "SUTRS"])
27
+ prefs.add("username", _("Username"), "", nil, false)
28
+ prefs.add("password", _("Password"), "", nil, false)
29
+ prefs.add("charset", _("Charset encoding"), "ISO-8859-1")
42
30
 
43
31
  # HACK : piggybacking support
44
- prefs.add('piggyback', 'Piggyback', true, [true, false])
32
+ prefs.add("piggyback", "Piggyback", true, [true, false])
45
33
  prefs.read
46
34
  end
47
35
 
48
36
  def search(criterion, type)
49
37
  prefs.read
50
- criterion = criterion.encode(prefs['charset'])
51
-
52
- # We only decode MARC at the moment.
53
- # SUTRS needs to be decoded separately, because each Z39.50 server has a
54
- # different one.
55
- raise NoResultsError unless marc?
38
+ criterion = criterion.encode(prefs["charset"])
56
39
 
57
40
  isbn = type == SEARCH_BY_ISBN ? criterion : nil
58
- criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
59
- conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
41
+ criterion = canonicalise_criterion(criterion, type)
42
+ conn_count = request_count(type)
60
43
  resultset = search_records(criterion, type, conn_count)
61
44
  log.debug { "total #{resultset.length}" }
62
- raise NoResultsError if resultset.length == 0
63
- results = books_from_marc(resultset, isbn)
45
+
46
+ results = books_from_resultset(resultset, isbn)
47
+ raise NoResultsError if results.empty?
48
+
64
49
  type == SEARCH_BY_ISBN ? results.first : results
65
50
  end
66
51
 
@@ -68,25 +53,51 @@ module Alexandria
68
53
  nil
69
54
  end
70
55
 
56
+ def books_from_resultset(resultset, isbn)
57
+ case prefs["record_syntax"]
58
+ when /MARC$/
59
+ books_from_marc(resultset, isbn)
60
+ when "SUTRS"
61
+ books_from_sutrs(resultset)
62
+ else
63
+ raise NoResultsError
64
+ end
65
+ end
66
+
71
67
  private
72
68
 
73
- def marc_to_book(marc_txt)
69
+ def request_count(type)
70
+ type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
71
+ end
72
+
73
+ def canonicalise_criterion(criterion, type)
74
+ criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
75
+ criterion
76
+ end
77
+
78
+ def books_from_sutrs(_resultset)
79
+ # SUTRS needs to be decoded separately, because each Z39.50 server has a
80
+ # different one.
81
+ raise NoResultsError
82
+ end
83
+
84
+ def marc_to_book(marc_txt, isbn)
74
85
  begin
75
86
  marc = MARC::Record.new_from_marc(marc_txt, forgiving: true)
76
- rescue => ex
87
+ rescue StandardError => ex
77
88
  log.error { ex.message }
78
89
  log.error { ex.backtrace.join("> \n") }
79
90
  begin
80
91
  marc = MARC::Record.new(marc_txt)
81
- rescue => ex2
82
- log.error { ex2.message }
83
- log.error { ex2.backtrace.join("> \n") }
84
- raise ex2
92
+ rescue StandardError => ex
93
+ log.error { ex.message }
94
+ log.error { ex.backtrace.join("> \n") }
95
+ raise ex
85
96
  end
86
97
  end
87
98
 
88
- log.debug {
89
- msg = 'Parsing MARC'
99
+ log.debug do
100
+ msg = "Parsing MARC"
90
101
  msg += "\n title: #{marc.title}"
91
102
  msg += "\n authors: #{marc.authors.join(', ')}"
92
103
  msg += "\n isbn: #{marc.isbn}, #{isbn}"
@@ -94,35 +105,34 @@ module Alexandria
94
105
  msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
95
106
  msg += "\n edition: #{marc.edition}"
96
107
  msg
97
- }
108
+ end
98
109
 
99
110
  return if marc.title.nil? # or marc.authors.empty?
100
111
 
101
- (isbn = isbn) || marc.isbn
112
+ isbn ||= marc.isbn
102
113
  isbn = Library.canonicalise_ean(isbn)
103
114
 
104
- book = Book.new(marc.title, marc.authors,
105
- isbn,
106
- (marc.publisher || ''),
107
- marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
108
- (marc.edition || ''))
109
- book
115
+ Book.new(marc.title, marc.authors,
116
+ isbn,
117
+ (marc.publisher || ""),
118
+ marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
119
+ (marc.edition || ""))
110
120
  end
111
121
 
112
- def books_from_marc(resultset, _isbn)
122
+ def books_from_marc(resultset, isbn)
113
123
  results = []
114
124
  resultset[0..9].each do |record|
115
- marc_txt = record.render(prefs['charset'], 'UTF-8') # (prefs['record_syntax'], 'USMARC')
125
+ marc_txt = record.render(prefs["charset"], "UTF-8")
116
126
  log.debug { marc_txt }
117
127
  if $DEBUG
118
- File.open(',marc.txt', 'wb') do |f| # DEBUG
128
+ File.open(",marc.txt", "wb") do |f| # DEBUG
119
129
  f.write(marc_txt)
120
130
  end
121
131
  end
122
132
  book = nil
123
133
  begin
124
134
  mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
125
- if prefs['hostname'] == 'z3950.bnf.fr'
135
+ if prefs["hostname"] == "z3950.bnf.fr"
126
136
  mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS
127
137
  end
128
138
  # try pseudo-marc parser first (it seems to have more luck)
@@ -130,9 +140,9 @@ module Alexandria
130
140
  mappings)
131
141
  if book.nil?
132
142
  # failing that, try the genuine MARC parser
133
- book = marc_to_book(marc_txt)
143
+ book = marc_to_book(marc_txt, isbn)
134
144
  end
135
- rescue => ex
145
+ rescue StandardError => ex
136
146
  log.warn { ex }
137
147
  log.warn { ex.backtrace }
138
148
  end
@@ -143,26 +153,23 @@ module Alexandria
143
153
  end
144
154
 
145
155
  def marc?
146
- /MARC$/.match(prefs['record_syntax'])
156
+ prefs["record_syntax"].end_with?("MARC")
147
157
  end
148
158
 
149
159
  def search_records(criterion, type, conn_count)
150
160
  options = {}
151
- unless prefs['username'].empty? || prefs['password'].empty?
152
- options['user'] = prefs['username']
153
- options['password'] = prefs['password']
161
+ unless prefs["username"].empty? || prefs["password"].empty?
162
+ options["user"] = prefs["username"]
163
+ options["password"] = prefs["password"]
154
164
  end
155
- hostname = prefs['hostname']
156
- port = prefs['port'].to_i
165
+ hostname = prefs["hostname"]
166
+ port = prefs["port"].to_i
157
167
  log.debug { "hostname #{hostname} port #{port} options #{options}" }
158
168
  conn = ZOOM::Connection.new(options).connect(hostname, port)
159
- conn.database_name = prefs['database']
169
+ conn.database_name = prefs["database"]
160
170
 
161
- # HACK: turn off piggybacking, just to see CMcG
162
- # #conn.piggyback = false
163
-
164
- conn.preferred_record_syntax = prefs['record_syntax']
165
- conn.element_set_name = 'F'
171
+ conn.preferred_record_syntax = prefs["record_syntax"]
172
+ conn.element_set_name = "F"
166
173
  conn.count = conn_count
167
174
  attr = case type
168
175
  when SEARCH_BY_ISBN then [7]
@@ -170,33 +177,27 @@ module Alexandria
170
177
  when SEARCH_BY_AUTHORS then [1, 1003]
171
178
  when SEARCH_BY_KEYWORD then [1016]
172
179
  end
173
- pqf = ''
180
+ pqf = ""
174
181
  attr.each { |att| pqf += "@attr 1=#{att} " }
175
182
  pqf += '"' + criterion.upcase + '"'
176
183
  log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
177
184
 
178
185
  begin
179
- if prefs.variable_named('piggyback')
180
- unless prefs['piggyback']
181
- log.debug { 'setting conn.piggyback to false' }
182
- conn.piggyback = false
183
- end
186
+ if prefs.variable_named("piggyback") && !prefs["piggyback"]
187
+ log.debug { "setting conn.piggyback to false" }
188
+ conn.piggyback = false
184
189
  end
185
190
  conn.search(pqf)
186
- rescue => ex
187
- if /1005/ =~ ex.message
188
- if prefs.variable_named('piggyback') && prefs['piggyback']
189
- log.error { "Z39.50 search failed:: #{ex.message}" }
190
- log.info { 'Turning off piggybacking for this provider' }
191
- prefs.variable_named('piggyback').new_value = false
192
- search_records(criterion, type, conn_count)
193
- # hopefully these precautions will prevent infinite loops here
194
- else
195
- raise ex
196
- end
197
- else
198
- raise ex
191
+ rescue StandardError => ex
192
+ if /1005/.match?(ex.message) &&
193
+ prefs.variable_named("piggyback") && prefs["piggyback"]
194
+ log.error { "Z39.50 search failed:: #{ex.message}" }
195
+ log.info { "Turning off piggybacking for this provider" }
196
+ prefs.variable_named("piggyback").new_value = false
197
+ retry
199
198
  end
199
+
200
+ raise ex
200
201
  end
201
202
  end
202
203
  end
@@ -206,21 +207,23 @@ module Alexandria
206
207
  unabstract
207
208
 
208
209
  include GetText
209
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
210
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
210
211
 
211
212
  def initialize
212
- super('LOC', _('Library of Congress (Usa)'))
213
- prefs.variable_named('hostname').default_value = 'z3950.loc.gov'
214
- prefs.variable_named('port').default_value = 7090
215
- prefs.variable_named('database').default_value = 'Voyager'
216
- prefs.variable_named('record_syntax').default_value = 'USMARC'
217
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
213
+ super("LOC", _("Library of Congress (Usa)"))
214
+ prefs.variable_named("hostname").default_value = "z3950.loc.gov"
215
+ prefs.variable_named("port").default_value = 7090
216
+ prefs.variable_named("database").default_value = "Voyager"
217
+ prefs.variable_named("record_syntax").default_value = "USMARC"
218
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
218
219
  prefs.read
219
220
  end
220
221
 
221
222
  def url(book)
222
- 'http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&CNT=25+records+per+page&CMD=isbn+' + Library.canonicalise_isbn(book.isbn)
223
- rescue => ex
223
+ isbn = Library.canonicalise_isbn(book.isbn)
224
+ "http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?" \
225
+ "DB=local&CNT=25+records+per+page&CMD=isbn+#{isbn}"
226
+ rescue StandardError => ex
224
227
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
225
228
  nil
226
229
  end
@@ -231,40 +234,30 @@ module Alexandria
231
234
  # http://en.wikipedia.org/wiki/British_Library
232
235
  # http://www.bl.uk/catalogues/z3950fullaccess.html
233
236
  # http://www.bl.uk/catalogues/z3950copacaccess.html
234
- # FIXME: switch from BL to Copac, which incudes the BL itself and many more libraries: http://copac.ac.uk/libraries/
237
+ #
238
+ # FIXME: switch from BL to Copac, which incudes the BL itself and many more
239
+ # libraries: http://copac.ac.uk/libraries/
240
+ #
235
241
  # Details: http://copac.ac.uk/interfaces/z39.50/
236
242
  # The SUTRS format used by Copac is different from the one used by BL
237
243
  unabstract
238
244
 
239
245
  include GetText
240
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
246
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
241
247
 
242
248
  def initialize
243
- super('BL', _('British Library'))
244
- prefs.variable_named('hostname').default_value = 'z3950cat.bl.uk'
245
- prefs.variable_named('port').default_value = 9909
246
- prefs.variable_named('database').default_value = 'BLAC'
247
- prefs.variable_named('record_syntax').default_value = 'SUTRS'
248
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
249
- prefs.read
250
- end
251
-
252
- def search(criterion, type)
253
- return super unless prefs['record_syntax'] == 'SUTRS'
254
-
249
+ super("BL", _("British Library"))
250
+ prefs.variable_named("hostname").default_value = "z3950cat.bl.uk"
251
+ prefs.variable_named("port").default_value = 9909
252
+ prefs.variable_named("database").default_value = "BLAC"
253
+ prefs.variable_named("record_syntax").default_value = "SUTRS"
254
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
255
255
  prefs.read
256
- criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
257
- conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
258
- resultset = search_records(criterion, type, conn_count)
259
- log.debug { "total #{resultset.length}" }
260
- raise NoResultsError if resultset.length == 0
261
- results = books_from_sutrs(resultset)
262
- type == SEARCH_BY_ISBN ? results.first : results
263
256
  end
264
257
 
265
258
  def url(book)
266
- 'http://copac.ac.uk/openurl?isbn=' + Library.canonicalise_isbn(book.isbn)
267
- rescue => ex
259
+ "http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn)
260
+ rescue StandardError => ex
268
261
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
269
262
  nil
270
263
  end
@@ -274,7 +267,7 @@ module Alexandria
274
267
  def books_from_sutrs(resultset)
275
268
  results = []
276
269
  resultset[0..9].each do |record|
277
- text = record.render(prefs['charset'], 'UTF-8')
270
+ text = record.render(prefs["charset"], "UTF-8")
278
271
  # File.open(',bl.marc', 'wb') {|f| f.write(text) }
279
272
  log.debug { text }
280
273
 
@@ -283,30 +276,31 @@ module Alexandria
283
276
 
284
277
  text.split(/\n/).each do |line|
285
278
  if (md = /^Title:\s+(.*)$/.match(line))
286
- title = md[1].sub(/\.$/, '').squeeze(' ')
279
+ title = md[1].sub(/\.$/, "").squeeze(" ")
287
280
  elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
288
281
  authors << md[1]
289
282
  elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
290
283
  authors << md[1]
291
284
  elsif (md = /^ISBN:\s+([\dXx]+)/.match(line))
292
285
  isbn = Library.canonicalise_ean(md[1])
293
- elsif (md = /^Imprint:.+\:\s*(.+)\,/.match(line))
286
+ elsif (md = /^Imprint:.+:\s*(.+),/.match(line))
294
287
  publisher = md[1]
295
288
  end
296
289
  end
297
290
 
298
- log.debug {
299
- msg = 'Parsing SUTRS'
291
+ log.debug do
292
+ msg = "Parsing SUTRS"
300
293
  msg += "\n title: #{title}"
301
294
  msg += "\n authors: #{authors.join(' and ')}"
302
295
  msg += "\n isbn: #{isbn}"
303
296
  msg += "\n publisher: #{publisher}"
304
297
  msg += "\n edition: #{edition}"
305
298
  msg
306
- }
299
+ end
307
300
 
308
301
  if title # and !authors.empty?
309
- book = Book.new(title, authors, isbn, (publisher || nil), (publish_year || nil), (edition || nil))
302
+ book = Book.new(title, authors, isbn, (publisher || nil),
303
+ (publish_year || nil), (edition || nil))
310
304
  results << [book]
311
305
  end
312
306
  end
@@ -320,83 +314,85 @@ module Alexandria
320
314
  unabstract
321
315
 
322
316
  include GetText
323
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
317
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
324
318
 
325
319
  def initialize
326
- super('SBN', 'Servizio Bibliotecario Nazionale (Italy)')
327
- prefs.variable_named('hostname').default_value = 'opac.sbn.it'
328
- prefs.variable_named('port').default_value = 3950
329
- prefs.variable_named('database').default_value = 'nopac'
320
+ super("SBN", "Servizio Bibliotecario Nazionale (Italy)")
321
+ prefs.variable_named("hostname").default_value = "opac.sbn.it"
322
+ prefs.variable_named("port").default_value = 3950
323
+ prefs.variable_named("database").default_value = "nopac"
330
324
  # supported 'USMARC', 'UNIMARC' , 'SUTRS'
331
- prefs.variable_named('record_syntax').default_value = 'USMARC'
332
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
325
+ prefs.variable_named("record_syntax").default_value = "USMARC"
326
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
333
327
  prefs.read
334
328
  end
335
329
 
336
- def search(criterion, type)
337
- prefs.read
338
-
339
- isbn = type == SEARCH_BY_ISBN ? criterion : nil
340
- criterion = canonicalise_isbn_with_dashes(criterion)
341
- resultset = search_records(criterion, type, 0)
342
- log.debug { "total #{resultset.length}" }
343
- raise NoResultsError if resultset.length == 0
344
- results = books_from_marc(resultset, isbn)
345
- type == SEARCH_BY_ISBN ? results.first : results
346
- end
347
-
348
330
  def url(book)
349
- 'http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=%253CB%253E%253Cfont%2520color%253D%2523000064%253E' \
350
- 'Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E' +
331
+ "http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=" \
332
+ "%253CB%253E%253Cfont%2520color%253D%2523000064%253E" \
333
+ "Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520" \
334
+ "contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E" +
351
335
  canonicalise_isbn_with_dashes(book.isbn) +
352
- '%253C%2FFONT%253E%2522&session=&zurl=opac&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22' +
336
+ "%253C%2FFONT%253E%2522&session=&zurl=opac" \
337
+ "&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22" +
353
338
  canonicalise_isbn_with_dashes(book.isbn) +
354
- '%22%29&language=it&maxentries=10&target=0&position=1'
355
- rescue => ex
339
+ "%22%29&language=it&maxentries=10&target=0&position=1"
340
+ rescue StandardError => ex
356
341
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
357
342
  nil
358
343
  end
359
344
 
360
345
  private
361
346
 
347
+ def canonicalise_criterion(criterion, _type)
348
+ canonicalise_isbn_with_dashes(criterion)
349
+ end
350
+
351
+ def request_count(_type)
352
+ 0
353
+ end
354
+
362
355
  def canonicalise_isbn_with_dashes(isbn)
363
356
  # The reference for the position of the dashes is
364
357
  # http://www.isbn-international.org/converter/ranges.htm
365
358
 
366
359
  isbn = Alexandria::Library.canonicalise_isbn(isbn)
367
360
 
368
- if isbn[0..1] == '88'
361
+ if isbn[0..1] == "88"
369
362
  # Italian speaking area
370
- if isbn > '8895000' && (isbn <= '8899999996')
371
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
372
- elsif isbn > '88900000'
373
- return isbn[0..1] + '-' + isbn[2..7] + '-' + isbn[8..8] + '-' + isbn[9..9]
374
- elsif isbn > '8885000'
375
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
376
- elsif isbn > '886000'
377
- return isbn[0..1] + '-' + isbn[2..5] + '-' + isbn[6..8] + '-' + isbn[9..9]
378
- elsif isbn > '88200'
379
- return isbn[0..1] + '-' + isbn[2..4] + '-' + isbn[5..8] + '-' + isbn[9..9]
380
- elsif isbn > '8800'
381
- return isbn[0..1] + '-' + isbn[2..3] + '-' + isbn[4..8] + '-' + isbn[9..9]
363
+ if isbn > "8895000" && (isbn <= "8899999996")
364
+ isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
365
+ elsif isbn > "88900000"
366
+ isbn[0..1] + "-" + isbn[2..7] + "-" + isbn[8..8] + "-" + isbn[9..9]
367
+ elsif isbn > "8885000"
368
+ isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
369
+ elsif isbn > "886000"
370
+ isbn[0..1] + "-" + isbn[2..5] + "-" + isbn[6..8] + "-" + isbn[9..9]
371
+ elsif isbn > "88200"
372
+ isbn[0..1] + "-" + isbn[2..4] + "-" + isbn[5..8] + "-" + isbn[9..9]
373
+ elsif isbn > "8800"
374
+ isbn[0..1] + "-" + isbn[2..3] + "-" + isbn[4..8] + "-" + isbn[9..9]
382
375
  else
383
- raise 'Invalid ISBN'
376
+ raise _("Invalid ISBN")
384
377
  end
385
378
 
386
379
  else
387
- return isbn
380
+ isbn
388
381
  end
389
382
  end
390
383
  #
391
384
  # Remarks about SBN
392
385
  #
393
- # This provider requires that value of conn.count is 0. It's a Yaz option "Number of records to be retrieved".
394
- # This provider requires to specify the value of conn.element_set_name = 'F'. It's a Yaz option "Element-Set name of records".
386
+ # This provider requires that value of conn.count is 0.
387
+ # It's a Yaz option "Number of records to be retrieved".
388
+ # This provider requires to specify the value of conn.element_set_name = 'F'.
389
+ # It's a Yaz option "Element-Set name of records".
395
390
  # See http://www.indexdata.dk/yaz/doc/zoom.resultsets.tkl
396
391
  #
397
392
  # Dashes:
398
393
  # this database requires that Italian books are searched with dashes :(
399
- # However, they have also books with dashes in wrong positions, for instance 88-061-4934-2
394
+ # However, they have also books with dashes in wrong positions, for
395
+ # instance 88-061-4934-2
400
396
  #
401
397
  # References:
402
398
  # http://opac.internetculturale.it/cgi-bin/main.cgi?type=field