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
@@ -1,68 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2005-2006 Laurent Sansonetti
4
- # Copyright (C) 2007 Laurent Sansonetti and Marco Costantini
5
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
3
+ # This file is part of Alexandria.
6
4
  #
7
- # Alexandria is free software; you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License as
9
- # published by the Free Software Foundation; either version 2 of the
10
- # License, or (at your option) any later version.
11
- #
12
- # Alexandria is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- # General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public
18
- # License along with Alexandria; see the file COPYING. If not,
19
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
20
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
21
6
 
22
7
  ## $Z3950_DEBUG = $DEBUG
23
8
 
24
- require 'zoom'
25
- require 'alexandria/book_providers/pseudomarc'
26
- require 'marc'
9
+ require "zoom"
10
+ require "alexandria/book_providers/pseudomarc"
11
+ require "marc"
27
12
 
28
13
  module Alexandria
29
14
  class BookProviders
30
15
  class Z3950Provider < AbstractProvider
31
16
  include Logging
32
17
  include GetText
33
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
18
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
34
19
 
35
- def initialize(name = 'Z3950', fullname = 'Z39.50')
20
+ def initialize(name = "Z3950", fullname = "Z39.50")
36
21
  super
37
- prefs.add('hostname', _('Hostname'), '')
38
- prefs.add('port', _('Port'), 7090)
39
- prefs.add('database', _('Database'), '')
40
- prefs.add('record_syntax', _('Record syntax'), 'USMARC', ['USMARC', 'UNIMARC', 'SUTRS'])
41
- prefs.add('username', _('Username'), '', nil, false)
42
- prefs.add('password', _('Password'), '', nil, false)
43
- 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")
44
30
 
45
31
  # HACK : piggybacking support
46
- prefs.add('piggyback', 'Piggyback', true, [true, false])
32
+ prefs.add("piggyback", "Piggyback", true, [true, false])
47
33
  prefs.read
48
34
  end
49
35
 
50
36
  def search(criterion, type)
51
37
  prefs.read
52
- criterion = criterion.encode(prefs['charset'])
53
-
54
- # We only decode MARC at the moment.
55
- # SUTRS needs to be decoded separately, because each Z39.50 server has a
56
- # different one.
57
- raise NoResultsError unless marc?
38
+ criterion = criterion.encode(prefs["charset"])
58
39
 
59
40
  isbn = type == SEARCH_BY_ISBN ? criterion : nil
60
- criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
61
- conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
41
+ criterion = canonicalise_criterion(criterion, type)
42
+ conn_count = request_count(type)
62
43
  resultset = search_records(criterion, type, conn_count)
63
44
  log.debug { "total #{resultset.length}" }
64
- raise NoResultsError if resultset.length == 0
65
- results = books_from_marc(resultset, isbn)
45
+
46
+ results = books_from_resultset(resultset, isbn)
47
+ raise NoResultsError if results.empty?
48
+
66
49
  type == SEARCH_BY_ISBN ? results.first : results
67
50
  end
68
51
 
@@ -70,25 +53,51 @@ module Alexandria
70
53
  nil
71
54
  end
72
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
+
73
67
  private
74
68
 
75
- 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)
76
85
  begin
77
86
  marc = MARC::Record.new_from_marc(marc_txt, forgiving: true)
78
- rescue => ex
87
+ rescue StandardError => ex
79
88
  log.error { ex.message }
80
89
  log.error { ex.backtrace.join("> \n") }
81
90
  begin
82
91
  marc = MARC::Record.new(marc_txt)
83
- rescue => ex2
84
- log.error { ex2.message }
85
- log.error { ex2.backtrace.join("> \n") }
86
- raise ex2
92
+ rescue StandardError => ex
93
+ log.error { ex.message }
94
+ log.error { ex.backtrace.join("> \n") }
95
+ raise ex
87
96
  end
88
97
  end
89
98
 
90
- log.debug {
91
- msg = 'Parsing MARC'
99
+ log.debug do
100
+ msg = "Parsing MARC"
92
101
  msg += "\n title: #{marc.title}"
93
102
  msg += "\n authors: #{marc.authors.join(', ')}"
94
103
  msg += "\n isbn: #{marc.isbn}, #{isbn}"
@@ -96,43 +105,44 @@ module Alexandria
96
105
  msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
97
106
  msg += "\n edition: #{marc.edition}"
98
107
  msg
99
- }
108
+ end
100
109
 
101
110
  return if marc.title.nil? # or marc.authors.empty?
102
111
 
103
- (isbn = isbn) || marc.isbn
112
+ isbn ||= marc.isbn
104
113
  isbn = Library.canonicalise_ean(isbn)
105
114
 
106
- book = Book.new(marc.title, marc.authors,
107
- isbn,
108
- (marc.publisher || ''),
109
- marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
110
- (marc.edition || ''))
111
- 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 || ""))
112
120
  end
113
121
 
114
- def books_from_marc(resultset, _isbn)
122
+ def books_from_marc(resultset, isbn)
115
123
  results = []
116
124
  resultset[0..9].each do |record|
117
- marc_txt = record.render(prefs['charset'], 'UTF-8') # (prefs['record_syntax'], 'USMARC')
125
+ marc_txt = record.render(prefs["charset"], "UTF-8")
118
126
  log.debug { marc_txt }
119
127
  if $DEBUG
120
- File.open(',marc.txt', 'wb') do |f| # DEBUG
128
+ File.open(",marc.txt", "wb") do |f| # DEBUG
121
129
  f.write(marc_txt)
122
130
  end
123
131
  end
124
132
  book = nil
125
133
  begin
126
134
  mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
127
- mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS if prefs['hostname'] == 'z3950.bnf.fr'
135
+ if prefs["hostname"] == "z3950.bnf.fr"
136
+ mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS
137
+ end
128
138
  # try pseudo-marc parser first (it seems to have more luck)
129
139
  book = Alexandria::PseudoMarcParser.marc_text_to_book(marc_txt,
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']
160
-
161
- # HACK: turn off piggybacking, just to see CMcG
162
- # #conn.piggyback = false
169
+ conn.database_name = prefs["database"]
163
170
 
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,22 +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+' +
223
- Library.canonicalise_isbn(book.isbn)
224
- 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
225
227
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
226
228
  nil
227
229
  end
@@ -241,34 +243,21 @@ module Alexandria
241
243
  unabstract
242
244
 
243
245
  include GetText
244
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
246
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
245
247
 
246
248
  def initialize
247
- super('BL', _('British Library'))
248
- prefs.variable_named('hostname').default_value = 'z3950cat.bl.uk'
249
- prefs.variable_named('port').default_value = 9909
250
- prefs.variable_named('database').default_value = 'BLAC'
251
- prefs.variable_named('record_syntax').default_value = 'SUTRS'
252
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
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"
253
255
  prefs.read
254
256
  end
255
257
 
256
- def search(criterion, type)
257
- return super unless prefs['record_syntax'] == 'SUTRS'
258
-
259
- prefs.read
260
- criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
261
- conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
262
- resultset = search_records(criterion, type, conn_count)
263
- log.debug { "total #{resultset.length}" }
264
- raise NoResultsError if resultset.length == 0
265
- results = books_from_sutrs(resultset)
266
- type == SEARCH_BY_ISBN ? results.first : results
267
- end
268
-
269
258
  def url(book)
270
- 'http://copac.ac.uk/openurl?isbn=' + Library.canonicalise_isbn(book.isbn)
271
- rescue => ex
259
+ "http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn)
260
+ rescue StandardError => ex
272
261
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
273
262
  nil
274
263
  end
@@ -278,7 +267,7 @@ module Alexandria
278
267
  def books_from_sutrs(resultset)
279
268
  results = []
280
269
  resultset[0..9].each do |record|
281
- text = record.render(prefs['charset'], 'UTF-8')
270
+ text = record.render(prefs["charset"], "UTF-8")
282
271
  # File.open(',bl.marc', 'wb') {|f| f.write(text) }
283
272
  log.debug { text }
284
273
 
@@ -287,27 +276,27 @@ module Alexandria
287
276
 
288
277
  text.split(/\n/).each do |line|
289
278
  if (md = /^Title:\s+(.*)$/.match(line))
290
- title = md[1].sub(/\.$/, '').squeeze(' ')
279
+ title = md[1].sub(/\.$/, "").squeeze(" ")
291
280
  elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
292
281
  authors << md[1]
293
282
  elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
294
283
  authors << md[1]
295
284
  elsif (md = /^ISBN:\s+([\dXx]+)/.match(line))
296
285
  isbn = Library.canonicalise_ean(md[1])
297
- elsif (md = /^Imprint:.+\:\s*(.+)\,/.match(line))
286
+ elsif (md = /^Imprint:.+:\s*(.+),/.match(line))
298
287
  publisher = md[1]
299
288
  end
300
289
  end
301
290
 
302
- log.debug {
303
- msg = 'Parsing SUTRS'
291
+ log.debug do
292
+ msg = "Parsing SUTRS"
304
293
  msg += "\n title: #{title}"
305
294
  msg += "\n authors: #{authors.join(' and ')}"
306
295
  msg += "\n isbn: #{isbn}"
307
296
  msg += "\n publisher: #{publisher}"
308
297
  msg += "\n edition: #{edition}"
309
298
  msg
310
- }
299
+ end
311
300
 
312
301
  if title # and !authors.empty?
313
302
  book = Book.new(title, authors, isbn, (publisher || nil),
@@ -325,73 +314,70 @@ module Alexandria
325
314
  unabstract
326
315
 
327
316
  include GetText
328
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
317
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
329
318
 
330
319
  def initialize
331
- super('SBN', 'Servizio Bibliotecario Nazionale (Italy)')
332
- prefs.variable_named('hostname').default_value = 'opac.sbn.it'
333
- prefs.variable_named('port').default_value = 3950
334
- 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"
335
324
  # supported 'USMARC', 'UNIMARC' , 'SUTRS'
336
- prefs.variable_named('record_syntax').default_value = 'USMARC'
337
- 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"
338
327
  prefs.read
339
328
  end
340
329
 
341
- def search(criterion, type)
342
- prefs.read
343
-
344
- isbn = type == SEARCH_BY_ISBN ? criterion : nil
345
- criterion = canonicalise_isbn_with_dashes(criterion)
346
- resultset = search_records(criterion, type, 0)
347
- log.debug { "total #{resultset.length}" }
348
- raise NoResultsError if resultset.length == 0
349
- results = books_from_marc(resultset, isbn)
350
- type == SEARCH_BY_ISBN ? results.first : results
351
- end
352
-
353
330
  def url(book)
354
- 'http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=' \
355
- '%253CB%253E%253Cfont%2520color%253D%2523000064%253E' \
356
- 'Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520' \
357
- 'contiene%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" +
358
335
  canonicalise_isbn_with_dashes(book.isbn) +
359
- '%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" +
360
338
  canonicalise_isbn_with_dashes(book.isbn) +
361
- '%22%29&language=it&maxentries=10&target=0&position=1'
362
- rescue => ex
339
+ "%22%29&language=it&maxentries=10&target=0&position=1"
340
+ rescue StandardError => ex
363
341
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
364
342
  nil
365
343
  end
366
344
 
367
345
  private
368
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
+
369
355
  def canonicalise_isbn_with_dashes(isbn)
370
356
  # The reference for the position of the dashes is
371
357
  # http://www.isbn-international.org/converter/ranges.htm
372
358
 
373
359
  isbn = Alexandria::Library.canonicalise_isbn(isbn)
374
360
 
375
- if isbn[0..1] == '88'
361
+ if isbn[0..1] == "88"
376
362
  # Italian speaking area
377
- if isbn > '8895000' && (isbn <= '8899999996')
378
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
379
- elsif isbn > '88900000'
380
- return isbn[0..1] + '-' + isbn[2..7] + '-' + isbn[8..8] + '-' + isbn[9..9]
381
- elsif isbn > '8885000'
382
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
383
- elsif isbn > '886000'
384
- return isbn[0..1] + '-' + isbn[2..5] + '-' + isbn[6..8] + '-' + isbn[9..9]
385
- elsif isbn > '88200'
386
- return isbn[0..1] + '-' + isbn[2..4] + '-' + isbn[5..8] + '-' + isbn[9..9]
387
- elsif isbn > '8800'
388
- 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]
389
375
  else
390
- raise 'Invalid ISBN'
376
+ raise _("Invalid ISBN")
391
377
  end
392
378
 
393
379
  else
394
- return isbn
380
+ isbn
395
381
  end
396
382
  end
397
383
  #
@@ -405,7 +391,8 @@ module Alexandria
405
391
  #
406
392
  # Dashes:
407
393
  # this database requires that Italian books are searched with dashes :(
408
- # 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
409
396
  #
410
397
  # References:
411
398
  # http://opac.internetculturale.it/cgi-bin/main.cgi?type=field