alexandria-book-collection-manager 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -25
  3. data/.rubocop_todo.yml +87 -67
  4. data/CHANGELOG.md +12 -1
  5. data/Gemfile +4 -3
  6. data/README.md +16 -6
  7. data/Rakefile +71 -72
  8. data/alexandria-book-collection-manager.gemspec +44 -44
  9. data/bin/alexandria +12 -12
  10. data/lib/alexandria.rb +22 -22
  11. data/lib/alexandria/about.rb +50 -50
  12. data/lib/alexandria/book_providers.rb +50 -50
  13. data/lib/alexandria/book_providers/adlibris.rb +28 -44
  14. data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
  15. data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
  16. data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
  17. data/lib/alexandria/book_providers/douban.rb +21 -37
  18. data/lib/alexandria/book_providers/proxis.rb +24 -24
  19. data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
  20. data/lib/alexandria/book_providers/renaud.rb +44 -57
  21. data/lib/alexandria/book_providers/siciliano.rb +39 -39
  22. data/lib/alexandria/book_providers/thalia.rb +33 -33
  23. data/lib/alexandria/book_providers/web.rb +5 -5
  24. data/lib/alexandria/book_providers/worldcat.rb +44 -69
  25. data/lib/alexandria/book_providers/z3950.rb +94 -109
  26. data/lib/alexandria/config.rb +1 -1
  27. data/lib/alexandria/console.rb +3 -3
  28. data/lib/alexandria/export_format.rb +8 -8
  29. data/lib/alexandria/export_library.rb +112 -113
  30. data/lib/alexandria/import_library.rb +45 -45
  31. data/lib/alexandria/import_library_csv.rb +30 -30
  32. data/lib/alexandria/library_collection.rb +4 -4
  33. data/lib/alexandria/library_sort_order.rb +1 -1
  34. data/lib/alexandria/library_store.rb +14 -14
  35. data/lib/alexandria/logging.rb +5 -5
  36. data/lib/alexandria/models/book.rb +1 -1
  37. data/lib/alexandria/models/library.rb +36 -36
  38. data/lib/alexandria/net.rb +5 -5
  39. data/lib/alexandria/preferences.rb +32 -32
  40. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
  41. data/lib/alexandria/scanners/keyboard.rb +5 -5
  42. data/lib/alexandria/smart_library.rb +53 -53
  43. data/lib/alexandria/ui.rb +15 -15
  44. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
  45. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
  46. data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
  47. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
  48. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
  49. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
  50. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
  51. data/lib/alexandria/ui/builder_base.rb +1 -1
  52. data/lib/alexandria/ui/callbacks.rb +95 -91
  53. data/lib/alexandria/ui/completion_models.rb +7 -21
  54. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  55. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  56. data/lib/alexandria/ui/dndable.rb +7 -7
  57. data/lib/alexandria/ui/error_dialog.rb +25 -0
  58. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +22 -42
  59. data/lib/alexandria/ui/icons.rb +6 -6
  60. data/lib/alexandria/ui/iconview.rb +7 -7
  61. data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
  62. data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
  63. data/lib/alexandria/ui/init.rb +16 -29
  64. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
  65. data/lib/alexandria/ui/libraries_combo.rb +7 -7
  66. data/lib/alexandria/ui/listview.rb +40 -40
  67. data/lib/alexandria/ui/main_app.rb +22 -24
  68. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  69. data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
  70. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
  71. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
  72. data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
  73. data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
  74. data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
  75. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
  76. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  77. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
  78. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
  79. data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
  80. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
  81. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
  82. data/lib/alexandria/ui/sound.rb +8 -8
  83. data/lib/alexandria/ui/ui_manager.rb +136 -135
  84. data/lib/alexandria/version.rb +4 -19
  85. data/lib/alexandria/web_themes.rb +8 -8
  86. data/po/cs.po +97 -97
  87. data/po/cy.po +97 -97
  88. data/po/de.po +97 -97
  89. data/po/el.po +97 -97
  90. data/po/es.po +97 -97
  91. data/po/fr.po +97 -97
  92. data/po/ga.po +97 -97
  93. data/po/gl.po +97 -97
  94. data/po/it.po +97 -97
  95. data/po/ja.po +97 -97
  96. data/po/mk.po +97 -97
  97. data/po/nb.po +97 -97
  98. data/po/nl.po +97 -97
  99. data/po/pl.po +97 -97
  100. data/po/pt.po +97 -97
  101. data/po/pt_BR.po +97 -97
  102. data/po/ru.po +97 -97
  103. data/po/sk.po +97 -97
  104. data/po/sv.po +97 -97
  105. data/po/uk.po +97 -97
  106. data/po/zh_TW.po +97 -97
  107. data/schemas/alexandria.schemas +24 -2
  108. data/spec/alexandria/book_providers_spec.rb +65 -82
  109. data/spec/alexandria/book_spec.rb +12 -10
  110. data/spec/alexandria/console_spec.rb +9 -9
  111. data/spec/alexandria/export_library_spec.rb +31 -31
  112. data/spec/alexandria/library_spec.rb +86 -86
  113. data/spec/alexandria/library_store_spec.rb +8 -8
  114. data/spec/alexandria/preferences_spec.rb +18 -17
  115. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  116. data/spec/alexandria/smart_library_spec.rb +15 -15
  117. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  118. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  119. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  120. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  121. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  122. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  123. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  124. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  125. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  126. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  127. data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
  128. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  129. data/spec/alexandria/ui/main_app_spec.rb +6 -6
  130. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  131. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  132. data/spec/alexandria/ui/new_provider_dialog_spec.rb +14 -0
  133. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
  134. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  135. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
  136. data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -0
  137. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  138. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  139. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +18 -0
  140. data/spec/alexandria/ui/sound_spec.rb +2 -2
  141. data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
  142. data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
  143. data/spec/alexandria/utilities_spec.rb +6 -6
  144. data/spec/end_to_end/basic_run_spec.rb +24 -36
  145. data/spec/spec_helper.rb +9 -9
  146. data/tasks/dogtail.rake +1 -1
  147. data/tasks/setup.rb +2 -2
  148. data/tasks/spec.rake +11 -11
  149. data/util/rake/fileinstall.rb +25 -25
  150. data/util/rake/gettextgenerate.rb +7 -7
  151. data/util/rake/omfgenerate.rb +7 -7
  152. metadata +59 -33
  153. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  154. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  155. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
@@ -1,55 +1,40 @@
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", ["USMARC", "UNIMARC", "SUTRS"])
26
+ prefs.add("username", _("Username"), "", nil, false)
27
+ prefs.add("password", _("Password"), "", nil, false)
28
+ prefs.add("charset", _("Charset encoding"), "ISO-8859-1")
44
29
 
45
30
  # HACK : piggybacking support
46
- prefs.add('piggyback', 'Piggyback', true, [true, false])
31
+ prefs.add("piggyback", "Piggyback", true, [true, false])
47
32
  prefs.read
48
33
  end
49
34
 
50
35
  def search(criterion, type)
51
36
  prefs.read
52
- criterion = criterion.encode(prefs['charset'])
37
+ criterion = criterion.encode(prefs["charset"])
53
38
 
54
39
  # We only decode MARC at the moment.
55
40
  # SUTRS needs to be decoded separately, because each Z39.50 server has a
@@ -81,15 +66,15 @@ module Alexandria
81
66
  log.error { ex.backtrace.join("> \n") }
82
67
  begin
83
68
  marc = MARC::Record.new(marc_txt)
84
- rescue StandardError => ex2
85
- log.error { ex2.message }
86
- log.error { ex2.backtrace.join("> \n") }
87
- raise ex2
69
+ rescue StandardError => ex
70
+ log.error { ex.message }
71
+ log.error { ex.backtrace.join("> \n") }
72
+ raise ex
88
73
  end
89
74
  end
90
75
 
91
- log.debug {
92
- msg = 'Parsing MARC'
76
+ log.debug do
77
+ msg = "Parsing MARC"
93
78
  msg += "\n title: #{marc.title}"
94
79
  msg += "\n authors: #{marc.authors.join(', ')}"
95
80
  msg += "\n isbn: #{marc.isbn}, #{isbn}"
@@ -97,7 +82,7 @@ module Alexandria
97
82
  msg += "\n publish year: #{marc.publish_year}" if marc.respond_to?(:publish_year)
98
83
  msg += "\n edition: #{marc.edition}"
99
84
  msg
100
- }
85
+ end
101
86
 
102
87
  return if marc.title.nil? # or marc.authors.empty?
103
88
 
@@ -106,26 +91,26 @@ module Alexandria
106
91
 
107
92
  book = Book.new(marc.title, marc.authors,
108
93
  isbn,
109
- (marc.publisher || ''),
94
+ (marc.publisher || ""),
110
95
  marc.respond_to?(:publish_year) ? marc.publish_year.to_i : nil,
111
- (marc.edition || ''))
96
+ (marc.edition || ""))
112
97
  book
113
98
  end
114
99
 
115
100
  def books_from_marc(resultset, _isbn)
116
101
  results = []
117
102
  resultset[0..9].each do |record|
118
- marc_txt = record.render(prefs['charset'], 'UTF-8') # (prefs['record_syntax'], 'USMARC')
103
+ marc_txt = record.render(prefs["charset"], "UTF-8") # (prefs['record_syntax'], 'USMARC')
119
104
  log.debug { marc_txt }
120
105
  if $DEBUG
121
- File.open(',marc.txt', 'wb') do |f| # DEBUG
106
+ File.open(",marc.txt", "wb") do |f| # DEBUG
122
107
  f.write(marc_txt)
123
108
  end
124
109
  end
125
110
  book = nil
126
111
  begin
127
112
  mappings = Alexandria::PseudoMarcParser::USMARC_MAPPINGS
128
- mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS if prefs['hostname'] == 'z3950.bnf.fr'
113
+ mappings = Alexandria::PseudoMarcParser::BNF_FR_MAPPINGS if prefs["hostname"] == "z3950.bnf.fr"
129
114
  # try pseudo-marc parser first (it seems to have more luck)
130
115
  book = Alexandria::PseudoMarcParser.marc_text_to_book(marc_txt,
131
116
  mappings)
@@ -144,26 +129,26 @@ module Alexandria
144
129
  end
145
130
 
146
131
  def marc?
147
- /MARC$/.match(prefs['record_syntax'])
132
+ /MARC$/.match(prefs["record_syntax"])
148
133
  end
149
134
 
150
135
  def search_records(criterion, type, conn_count)
151
136
  options = {}
152
- unless prefs['username'].empty? || prefs['password'].empty?
153
- options['user'] = prefs['username']
154
- options['password'] = prefs['password']
137
+ unless prefs["username"].empty? || prefs["password"].empty?
138
+ options["user"] = prefs["username"]
139
+ options["password"] = prefs["password"]
155
140
  end
156
- hostname = prefs['hostname']
157
- port = prefs['port'].to_i
141
+ hostname = prefs["hostname"]
142
+ port = prefs["port"].to_i
158
143
  log.debug { "hostname #{hostname} port #{port} options #{options}" }
159
144
  conn = ZOOM::Connection.new(options).connect(hostname, port)
160
- conn.database_name = prefs['database']
145
+ conn.database_name = prefs["database"]
161
146
 
162
147
  # HACK: turn off piggybacking, just to see CMcG
163
148
  # #conn.piggyback = false
164
149
 
165
- conn.preferred_record_syntax = prefs['record_syntax']
166
- conn.element_set_name = 'F'
150
+ conn.preferred_record_syntax = prefs["record_syntax"]
151
+ conn.element_set_name = "F"
167
152
  conn.count = conn_count
168
153
  attr = case type
169
154
  when SEARCH_BY_ISBN then [7]
@@ -171,25 +156,25 @@ module Alexandria
171
156
  when SEARCH_BY_AUTHORS then [1, 1003]
172
157
  when SEARCH_BY_KEYWORD then [1016]
173
158
  end
174
- pqf = ''
159
+ pqf = ""
175
160
  attr.each { |att| pqf += "@attr 1=#{att} " }
176
161
  pqf += '"' + criterion.upcase + '"'
177
162
  log.debug { "pqf is #{pqf}, syntax #{prefs['record_syntax']}" }
178
163
 
179
164
  begin
180
- if prefs.variable_named('piggyback')
181
- unless prefs['piggyback']
182
- log.debug { 'setting conn.piggyback to false' }
165
+ if prefs.variable_named("piggyback")
166
+ unless prefs["piggyback"]
167
+ log.debug { "setting conn.piggyback to false" }
183
168
  conn.piggyback = false
184
169
  end
185
170
  end
186
171
  conn.search(pqf)
187
172
  rescue StandardError => ex
188
- if /1005/ =~ ex.message
189
- if prefs.variable_named('piggyback') && prefs['piggyback']
173
+ if /1005/.match?(ex.message)
174
+ if prefs.variable_named("piggyback") && prefs["piggyback"]
190
175
  log.error { "Z39.50 search failed:: #{ex.message}" }
191
- log.info { 'Turning off piggybacking for this provider' }
192
- prefs.variable_named('piggyback').new_value = false
176
+ log.info { "Turning off piggybacking for this provider" }
177
+ prefs.variable_named("piggyback").new_value = false
193
178
  search_records(criterion, type, conn_count)
194
179
  # hopefully these precautions will prevent infinite loops here
195
180
  else
@@ -207,20 +192,20 @@ module Alexandria
207
192
  unabstract
208
193
 
209
194
  include GetText
210
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
195
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
211
196
 
212
197
  def initialize
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'
198
+ super("LOC", _("Library of Congress (Usa)"))
199
+ prefs.variable_named("hostname").default_value = "z3950.loc.gov"
200
+ prefs.variable_named("port").default_value = 7090
201
+ prefs.variable_named("database").default_value = "Voyager"
202
+ prefs.variable_named("record_syntax").default_value = "USMARC"
203
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
219
204
  prefs.read
220
205
  end
221
206
 
222
207
  def url(book)
223
- 'http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&CNT=25+records+per+page&CMD=isbn+' +
208
+ "http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&CNT=25+records+per+page&CMD=isbn+" +
224
209
  Library.canonicalise_isbn(book.isbn)
225
210
  rescue StandardError => ex
226
211
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
@@ -242,20 +227,20 @@ module Alexandria
242
227
  unabstract
243
228
 
244
229
  include GetText
245
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
230
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
246
231
 
247
232
  def initialize
248
- super('BL', _('British Library'))
249
- prefs.variable_named('hostname').default_value = 'z3950cat.bl.uk'
250
- prefs.variable_named('port').default_value = 9909
251
- prefs.variable_named('database').default_value = 'BLAC'
252
- prefs.variable_named('record_syntax').default_value = 'SUTRS'
253
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
233
+ super("BL", _("British Library"))
234
+ prefs.variable_named("hostname").default_value = "z3950cat.bl.uk"
235
+ prefs.variable_named("port").default_value = 9909
236
+ prefs.variable_named("database").default_value = "BLAC"
237
+ prefs.variable_named("record_syntax").default_value = "SUTRS"
238
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
254
239
  prefs.read
255
240
  end
256
241
 
257
242
  def search(criterion, type)
258
- return super unless prefs['record_syntax'] == 'SUTRS'
243
+ return super unless prefs["record_syntax"] == "SUTRS"
259
244
 
260
245
  prefs.read
261
246
  criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
@@ -269,7 +254,7 @@ module Alexandria
269
254
  end
270
255
 
271
256
  def url(book)
272
- 'http://copac.ac.uk/openurl?isbn=' + Library.canonicalise_isbn(book.isbn)
257
+ "http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn)
273
258
  rescue StandardError => ex
274
259
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
275
260
  nil
@@ -280,7 +265,7 @@ module Alexandria
280
265
  def books_from_sutrs(resultset)
281
266
  results = []
282
267
  resultset[0..9].each do |record|
283
- text = record.render(prefs['charset'], 'UTF-8')
268
+ text = record.render(prefs["charset"], "UTF-8")
284
269
  # File.open(',bl.marc', 'wb') {|f| f.write(text) }
285
270
  log.debug { text }
286
271
 
@@ -289,7 +274,7 @@ module Alexandria
289
274
 
290
275
  text.split(/\n/).each do |line|
291
276
  if (md = /^Title:\s+(.*)$/.match(line))
292
- title = md[1].sub(/\.$/, '').squeeze(' ')
277
+ title = md[1].sub(/\.$/, "").squeeze(" ")
293
278
  elsif (md = /^Added Person Name:\s+(.*),[^,]+$/.match(line))
294
279
  authors << md[1]
295
280
  elsif (md = /^ME-Personal Name:\s+(.*),[^,]+$/.match(line))
@@ -301,15 +286,15 @@ module Alexandria
301
286
  end
302
287
  end
303
288
 
304
- log.debug {
305
- msg = 'Parsing SUTRS'
289
+ log.debug do
290
+ msg = "Parsing SUTRS"
306
291
  msg += "\n title: #{title}"
307
292
  msg += "\n authors: #{authors.join(' and ')}"
308
293
  msg += "\n isbn: #{isbn}"
309
294
  msg += "\n publisher: #{publisher}"
310
295
  msg += "\n edition: #{edition}"
311
296
  msg
312
- }
297
+ end
313
298
 
314
299
  if title # and !authors.empty?
315
300
  book = Book.new(title, authors, isbn, (publisher || nil),
@@ -327,16 +312,16 @@ module Alexandria
327
312
  unabstract
328
313
 
329
314
  include GetText
330
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
315
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
331
316
 
332
317
  def initialize
333
- super('SBN', 'Servizio Bibliotecario Nazionale (Italy)')
334
- prefs.variable_named('hostname').default_value = 'opac.sbn.it'
335
- prefs.variable_named('port').default_value = 3950
336
- prefs.variable_named('database').default_value = 'nopac'
318
+ super("SBN", "Servizio Bibliotecario Nazionale (Italy)")
319
+ prefs.variable_named("hostname").default_value = "opac.sbn.it"
320
+ prefs.variable_named("port").default_value = 3950
321
+ prefs.variable_named("database").default_value = "nopac"
337
322
  # supported 'USMARC', 'UNIMARC' , 'SUTRS'
338
- prefs.variable_named('record_syntax').default_value = 'USMARC'
339
- prefs.variable_named('charset').default_value = 'ISO-8859-1'
323
+ prefs.variable_named("record_syntax").default_value = "USMARC"
324
+ prefs.variable_named("charset").default_value = "ISO-8859-1"
340
325
  prefs.read
341
326
  end
342
327
 
@@ -354,14 +339,14 @@ module Alexandria
354
339
  end
355
340
 
356
341
  def url(book)
357
- 'http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=' \
358
- '%253CB%253E%253Cfont%2520color%253D%2523000064%253E' \
359
- 'Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520' \
360
- 'contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E' +
342
+ "http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=" \
343
+ "%253CB%253E%253Cfont%2520color%253D%2523000064%253E" \
344
+ "Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520" \
345
+ "contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E" +
361
346
  canonicalise_isbn_with_dashes(book.isbn) +
362
- '%253C%2FFONT%253E%2522&session=&zurl=opac&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22' +
347
+ "%253C%2FFONT%253E%2522&session=&zurl=opac&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22" +
363
348
  canonicalise_isbn_with_dashes(book.isbn) +
364
- '%22%29&language=it&maxentries=10&target=0&position=1'
349
+ "%22%29&language=it&maxentries=10&target=0&position=1"
365
350
  rescue StandardError => ex
366
351
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
367
352
  nil
@@ -375,22 +360,22 @@ module Alexandria
375
360
 
376
361
  isbn = Alexandria::Library.canonicalise_isbn(isbn)
377
362
 
378
- if isbn[0..1] == '88'
363
+ if isbn[0..1] == "88"
379
364
  # Italian speaking area
380
- if isbn > '8895000' && (isbn <= '8899999996')
381
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
382
- elsif isbn > '88900000'
383
- return isbn[0..1] + '-' + isbn[2..7] + '-' + isbn[8..8] + '-' + isbn[9..9]
384
- elsif isbn > '8885000'
385
- return isbn[0..1] + '-' + isbn[2..6] + '-' + isbn[7..8] + '-' + isbn[9..9]
386
- elsif isbn > '886000'
387
- return isbn[0..1] + '-' + isbn[2..5] + '-' + isbn[6..8] + '-' + isbn[9..9]
388
- elsif isbn > '88200'
389
- return isbn[0..1] + '-' + isbn[2..4] + '-' + isbn[5..8] + '-' + isbn[9..9]
390
- elsif isbn > '8800'
391
- return isbn[0..1] + '-' + isbn[2..3] + '-' + isbn[4..8] + '-' + isbn[9..9]
365
+ if isbn > "8895000" && (isbn <= "8899999996")
366
+ return isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
367
+ elsif isbn > "88900000"
368
+ return isbn[0..1] + "-" + isbn[2..7] + "-" + isbn[8..8] + "-" + isbn[9..9]
369
+ elsif isbn > "8885000"
370
+ return isbn[0..1] + "-" + isbn[2..6] + "-" + isbn[7..8] + "-" + isbn[9..9]
371
+ elsif isbn > "886000"
372
+ return isbn[0..1] + "-" + isbn[2..5] + "-" + isbn[6..8] + "-" + isbn[9..9]
373
+ elsif isbn > "88200"
374
+ return isbn[0..1] + "-" + isbn[2..4] + "-" + isbn[5..8] + "-" + isbn[9..9]
375
+ elsif isbn > "8800"
376
+ return isbn[0..1] + "-" + isbn[2..3] + "-" + isbn[4..8] + "-" + isbn[9..9]
392
377
  else
393
- raise 'Invalid ISBN'
378
+ raise "Invalid ISBN"
394
379
  end
395
380
 
396
381
  else
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Alexandria
4
4
  module Config
5
- SHARE_DIR = File.expand_path('../../share', File.dirname(__FILE__))
5
+ SHARE_DIR = File.expand_path("../../share", File.dirname(__FILE__))
6
6
  SOUNDS_DIR = "#{SHARE_DIR}/sounds/alexandria"
7
7
  DATA_DIR = "#{SHARE_DIR}/alexandria"
8
8
  MAIN_DATA_DIR = DATA_DIR
@@ -9,11 +9,11 @@ module Alexandria
9
9
  collection = Alexandria::LibraryCollection.instance
10
10
  collection.reload
11
11
  libraries = collection.all_regular_libraries
12
- output_string = ''
12
+ output_string = ""
13
13
  @books = libraries.flatten
14
14
  @books.each do |book|
15
- book_authors = book.authors.join(' & ') if authors
16
- output_string += [book.title, book_authors].join(', ') + "\n"
15
+ book_authors = book.authors.join(" & ") if authors
16
+ output_string += [book.title, book_authors].join(", ") + "\n"
17
17
  end
18
18
  output_string
19
19
  end
@@ -11,17 +11,17 @@ module Alexandria
11
11
  include GetText
12
12
  include Logging
13
13
  extend GetText
14
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
14
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
15
15
 
16
16
  def self.all
17
17
  [
18
- new(_('Archived ONIX XML'), 'onix.tbz2', :export_as_onix_xml_archive),
19
- new(_('Archived Tellico XML'), 'tc', :export_as_tellico_xml_archive),
20
- new(_('BibTeX'), 'bib', :export_as_bibtex),
21
- new(_('CSV list'), 'csv', :export_as_csv_list),
22
- new(_('ISBN List'), 'txt', :export_as_isbn_list),
23
- new(_('iPod Notes'), nil, :export_as_ipod_notes),
24
- new(_('HTML Web Page'), nil, :export_as_html, true)
18
+ new(_("Archived ONIX XML"), "onix.tbz2", :export_as_onix_xml_archive),
19
+ new(_("Archived Tellico XML"), "tc", :export_as_tellico_xml_archive),
20
+ new(_("BibTeX"), "bib", :export_as_bibtex),
21
+ new(_("CSV list"), "csv", :export_as_csv_list),
22
+ new(_("ISBN List"), "txt", :export_as_isbn_list),
23
+ new(_("iPod Notes"), nil, :export_as_ipod_notes),
24
+ new(_("HTML Web Page"), nil, :export_as_html, true)
25
25
  ]
26
26
  end
27
27
 
@@ -4,9 +4,9 @@
4
4
  #
5
5
  # See the file README.md for authorship and licensing information.
6
6
 
7
- require 'csv'
8
- require 'image_size'
9
- require 'tmpdir'
7
+ require "csv"
8
+ require "image_size"
9
+ require "tmpdir"
10
10
 
11
11
  module Alexandria
12
12
  class ExportLibrary
@@ -36,20 +36,20 @@ module Alexandria
36
36
  end
37
37
 
38
38
  def export_as_onix_xml_archive(filename)
39
- File.open(File.join(Dir.tmpdir, 'onix.xml'), 'w') do |io|
39
+ File.open(File.join(Dir.tmpdir, "onix.xml"), "w") do |io|
40
40
  to_onix_document.write(io, 0)
41
41
  end
42
- copy_covers(File.join(Dir.tmpdir, 'images'))
42
+ copy_covers(File.join(Dir.tmpdir, "images"))
43
43
  Dir.chdir(Dir.tmpdir) do
44
44
  output = `tar -cjf \"#{filename}\" onix.xml images 2>&1`
45
45
  raise output unless $CHILD_STATUS.success?
46
46
  end
47
- FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
48
- FileUtils.rm(File.join(Dir.tmpdir, 'onix.xml'))
47
+ FileUtils.rm_rf(File.join(Dir.tmpdir, "images"))
48
+ FileUtils.rm(File.join(Dir.tmpdir, "onix.xml"))
49
49
  end
50
50
 
51
51
  def export_as_tellico_xml_archive(filename)
52
- File.open(File.join(Dir.tmpdir, 'tellico.xml'), 'w') do |io|
52
+ File.open(File.join(Dir.tmpdir, "tellico.xml"), "w") do |io|
53
53
  begin
54
54
  to_tellico_document.write(io, 0)
55
55
  rescue StandardError => ex
@@ -58,19 +58,19 @@ module Alexandria
58
58
  raise ex
59
59
  end
60
60
  end
61
- copy_covers(File.join(Dir.tmpdir, 'images'))
61
+ copy_covers(File.join(Dir.tmpdir, "images"))
62
62
  Dir.chdir(Dir.tmpdir) do
63
63
  output = `zip -q -r \"#{filename}\" tellico.xml images 2>&1`
64
64
  raise output unless $CHILD_STATUS.success?
65
65
  end
66
- FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
67
- FileUtils.rm(File.join(Dir.tmpdir, 'tellico.xml'))
66
+ FileUtils.rm_rf(File.join(Dir.tmpdir, "images"))
67
+ FileUtils.rm(File.join(Dir.tmpdir, "tellico.xml"))
68
68
  end
69
69
 
70
70
  def export_as_isbn_list(filename)
71
- File.open(filename, 'w') do |io|
71
+ File.open(filename, "w") do |io|
72
72
  each do |book|
73
- io.puts((book.isbn || ''))
73
+ io.puts((book.isbn || ""))
74
74
  end
75
75
  end
76
76
  end
@@ -78,17 +78,17 @@ module Alexandria
78
78
  def export_as_html(filename, theme)
79
79
  FileUtils.mkdir(filename) unless File.exist?(filename)
80
80
  Dir.chdir(filename) do
81
- copy_covers('pixmaps')
82
- FileUtils.cp_r(theme.pixmaps_directory, 'pixmaps') if theme.has_pixmaps?
83
- FileUtils.cp(theme.css_file, '.')
84
- File.open('index.html', 'w') do |io|
81
+ copy_covers("pixmaps")
82
+ FileUtils.cp_r(theme.pixmaps_directory, "pixmaps") if theme.has_pixmaps?
83
+ FileUtils.cp(theme.css_file, ".")
84
+ File.open("index.html", "w") do |io|
85
85
  io << to_xhtml(File.basename(theme.css_file))
86
86
  end
87
87
  end
88
88
  end
89
89
 
90
90
  def export_as_bibtex(filename)
91
- File.open(filename, 'w') do |io|
91
+ File.open(filename, "w") do |io|
92
92
  io << to_bibtex
93
93
  end
94
94
  end
@@ -97,26 +97,26 @@ module Alexandria
97
97
  FileUtils.mkdir(filename) unless File.exist?(filename)
98
98
  tempdir = Dir.getwd
99
99
  Dir.chdir(filename)
100
- copy_covers('pixmaps')
101
- File.open('index.linx', 'w') do |io|
102
- io.puts '<TITLE>' + name + '</TITLE>'
100
+ copy_covers("pixmaps")
101
+ File.open("index.linx", "w") do |io|
102
+ io.puts "<TITLE>" + name + "</TITLE>"
103
103
  each do |book|
104
- io.puts '<A HREF="' + book.ident + '">' + book.title + '</A>'
104
+ io.puts '<A HREF="' + book.ident + '">' + book.title + "</A>"
105
105
  end
106
106
  io.close
107
107
  end
108
108
  each do |book|
109
- File.open(book.ident, 'w') do |io|
109
+ File.open(book.ident, "w") do |io|
110
110
  io.puts "<TITLE>#{book.title} </TITLE>"
111
111
  # put a link to the book's cover. only works on iPod 5G and above(?).
112
112
  if File.exist?(cover(book))
113
- io.puts '<A HREF="pixmaps/' + book.ident + '.jpg' + '">' + book.title + '</A>'
113
+ io.puts '<A HREF="pixmaps/' + book.ident + ".jpg" + '">' + book.title + "</A>"
114
114
  else
115
115
  io.puts book.title
116
116
  end
117
- io.puts book.authors.join(', ')
117
+ io.puts book.authors.join(", ")
118
118
  io.puts book.edition
119
- io.puts((book.isbn || ''))
119
+ io.puts((book.isbn || ""))
120
120
  # we need to close the files so the iPod can be ejected/unmounted without us closing Alexandria
121
121
  io.close
122
122
  end
@@ -126,84 +126,83 @@ module Alexandria
126
126
  end
127
127
 
128
128
  def export_as_csv_list(filename)
129
- CSV.open(filename, 'w', col_sep: ';') do |csv|
130
- csv << ['Title', 'Authors', 'Publisher', 'Edition', 'ISBN', 'Year Published',
131
- "Rating(#{Book::DEFAULT_RATING} to #{Book::MAX_RATING_STARS})", 'Notes',
132
- 'Want?', 'Read?', 'Own?', 'Tags']
129
+ CSV.open(filename, "w", col_sep: ";") do |csv|
130
+ csv << ["Title", "Authors", "Publisher", "Edition", "ISBN", "Year Published",
131
+ "Rating(#{Book::DEFAULT_RATING} to #{Book::MAX_RATING_STARS})", "Notes",
132
+ "Want?", "Read?", "Own?", "Tags"]
133
133
  each do |book|
134
- csv << [book.title, book.authors.join(', '), book.publisher, book.edition, book.isbn,
134
+ csv << [book.title, book.authors.join(", "), book.publisher, book.edition, book.isbn,
135
135
  book.publishing_year, book.rating, book.notes,
136
- (book.want ? '1' : '0'), (book.redd ? '1' : '0'), (book.own ? '1' : '0'),
137
- (book.tags ? book.tags.join(', ') : '')]
136
+ (book.want ? "1" : "0"), (book.redd ? "1" : "0"), (book.own ? "1" : "0"),
137
+ (book.tags ? book.tags.join(", ") : "")]
138
138
  end
139
139
  end
140
140
  end
141
141
 
142
142
  private
143
143
 
144
- ONIX_DTD_URL = 'http://www.editeur.org/onix/2.1/reference/onix-international.dtd'
144
+ ONIX_DTD_URL = "http://www.editeur.org/onix/2.1/reference/onix-international.dtd"
145
145
  def to_onix_document
146
146
  doc = REXML::Document.new
147
147
  doc << REXML::XMLDecl.new
148
- doc << REXML::DocType.new('ONIXMessage',
148
+ doc << REXML::DocType.new("ONIXMessage",
149
149
  "SYSTEM \"#{ONIX_DTD_URL}\"")
150
- msg = doc.add_element('ONIXMessage')
151
- header = msg.add_element('Header')
152
- header.add_element('FromCompany').text = 'Alexandria'
153
- header.add_element('FromPerson').text = Etc.getlogin
150
+ msg = doc.add_element("ONIXMessage")
151
+ header = msg.add_element("Header")
152
+ header.add_element("FromCompany").text = "Alexandria"
153
+ header.add_element("FromPerson").text = Etc.getlogin
154
154
  now = Time.now
155
- header.add_element('SentDate').text = format('%.4d%.2d%.2d%.2d%.2d',
156
- now.year, now.month, now.day, now.hour, now.min)
157
- header.add_element('MessageNote').text = name
155
+ header.add_element("SentDate").text = now.strftime("%Y%m%d%H%M")
156
+ header.add_element("MessageNote").text = name
158
157
  @sorted.each_with_index do |book, idx|
159
158
  # fields that are missing: edition and rating.
160
- prod = msg.add_element('Product')
161
- prod.add_element('RecordReference').text = idx
162
- prod.add_element('NotificationType').text = '03' # confirmed
163
- prod.add_element('RecordSourceName').text =
164
- 'Alexandria ' + Alexandria::DISPLAY_VERSION
165
- prod.add_element('ISBN').text = (book.isbn || '')
166
- prod.add_element('ProductForm').text = 'BA' # book
167
- prod.add_element('DistinctiveTitle').text = book.title
159
+ prod = msg.add_element("Product")
160
+ prod.add_element("RecordReference").text = idx
161
+ prod.add_element("NotificationType").text = "03" # confirmed
162
+ prod.add_element("RecordSourceName").text =
163
+ "Alexandria " + Alexandria::DISPLAY_VERSION
164
+ prod.add_element("ISBN").text = (book.isbn || "")
165
+ prod.add_element("ProductForm").text = "BA" # book
166
+ prod.add_element("DistinctiveTitle").text = book.title
168
167
  unless book.authors.empty?
169
168
  book.authors.each do |author|
170
- elem = prod.add_element('Contributor')
169
+ elem = prod.add_element("Contributor")
171
170
  # author
172
- elem.add_element('ContributorRole').text = 'A01'
173
- elem.add_element('PersonName').text = author
171
+ elem.add_element("ContributorRole").text = "A01"
172
+ elem.add_element("PersonName").text = author
174
173
  end
175
174
  end
176
175
  if book.notes && !book.notes.empty?
177
- elem = prod.add_element('OtherText')
176
+ elem = prod.add_element("OtherText")
178
177
  # reader description
179
- elem.add_element('TextTypeCode').text = '12'
180
- elem.add_element('TextFormat').text = '00' # ASCII
181
- elem.add_element('Text').text = book.notes
178
+ elem.add_element("TextTypeCode").text = "12"
179
+ elem.add_element("TextFormat").text = "00" # ASCII
180
+ elem.add_element("Text").text = book.notes
182
181
  end
183
182
  if File.exist?(cover(book))
184
- elem = prod.add_element('MediaFile')
183
+ elem = prod.add_element("MediaFile")
185
184
  # front cover image
186
- elem.add_element('MediaFileTypeCode').text = '04'
187
- elem.add_element('MediaFileFormatCode').text =
188
- (Library.jpeg?(cover(book)) ? '03' : '02')
185
+ elem.add_element("MediaFileTypeCode").text = "04"
186
+ elem.add_element("MediaFileFormatCode").text =
187
+ (Library.jpeg?(cover(book)) ? "03" : "02")
189
188
  # filename
190
- elem.add_element('MediaFileLinkTypeCode').text = '06'
191
- elem.add_element('MediaFileLink').text =
192
- File.join('images', final_cover(book))
189
+ elem.add_element("MediaFileLinkTypeCode").text = "06"
190
+ elem.add_element("MediaFileLink").text =
191
+ File.join("images", final_cover(book))
193
192
  end
194
193
  if book.isbn
195
194
  BookProviders.each do |provider|
196
- elem = prod.add_element('ProductWebsite')
197
- elem.add_element('ProductWebsiteDescription').text =
195
+ elem = prod.add_element("ProductWebsite")
196
+ elem.add_element("ProductWebsiteDescription").text =
198
197
  provider.fullname
199
- elem.add_element('ProductWebsiteLink').text =
198
+ elem.add_element("ProductWebsiteLink").text =
200
199
  provider.url(book)
201
200
  end
202
201
  end
203
- elem = prod.add_element('Publisher')
204
- elem.add_element('PublishingRole').text = '01'
205
- elem.add_element('PublisherName').text = book.publisher
206
- prod.add_element('PublicationDate').text = book.publishing_year
202
+ elem = prod.add_element("Publisher")
203
+ elem.add_element("PublishingRole").text = "01"
204
+ elem.add_element("PublisherName").text = book.publisher
205
+ prod.add_element("PublicationDate").text = book.publishing_year
207
206
  end
208
207
  doc
209
208
  end
@@ -213,49 +212,49 @@ module Alexandria
213
212
  # http://periapsis.org/tellico/doc/hacking.html
214
213
  doc = REXML::Document.new
215
214
  doc << REXML::XMLDecl.new
216
- doc << REXML::DocType.new('tellico',
215
+ doc << REXML::DocType.new("tellico",
217
216
  'PUBLIC "-//Robby Stephenson/DTD Tellico V7.0//EN"' \
218
217
  ' "http://periapsis.org/tellico/dtd/v7/tellico.dtd"')
219
- tellico = doc.add_element('tellico')
220
- tellico.add_attribute('syntaxVersion', '7')
221
- tellico.add_namespace('http://periapsis.org/tellico/')
222
- collection = tellico.add_element('collection')
223
- collection.add_attribute('title', name)
224
- collection.add_attribute('type', '2')
225
- fields = collection.add_element('fields')
226
- field1 = fields.add_element('field')
218
+ tellico = doc.add_element("tellico")
219
+ tellico.add_attribute("syntaxVersion", "7")
220
+ tellico.add_namespace("http://periapsis.org/tellico/")
221
+ collection = tellico.add_element("collection")
222
+ collection.add_attribute("title", name)
223
+ collection.add_attribute("type", "2")
224
+ fields = collection.add_element("fields")
225
+ field1 = fields.add_element("field")
227
226
  # a field named _default implies adding all default book
228
227
  # collection fields
229
- field1.add_attribute('name', '_default')
230
- images = collection.add_element('images')
228
+ field1.add_attribute("name", "_default")
229
+ images = collection.add_element("images")
231
230
  @sorted.each_with_index do |book, idx|
232
- entry = collection.add_element('entry')
231
+ entry = collection.add_element("entry")
233
232
  new_index = (idx + 1).to_s
234
- entry.add_attribute('id', new_index)
233
+ entry.add_attribute("id", new_index)
235
234
  # translate the binding
236
- entry.add_element('title').text = book.title
237
- entry.add_element('isbn').text = (book.isbn || '')
238
- entry.add_element('pub_year').text = book.publishing_year
239
- entry.add_element('binding').text = book.edition
240
- entry.add_element('publisher').text = book.publisher
235
+ entry.add_element("title").text = book.title
236
+ entry.add_element("isbn").text = (book.isbn || "")
237
+ entry.add_element("pub_year").text = book.publishing_year
238
+ entry.add_element("binding").text = book.edition
239
+ entry.add_element("publisher").text = book.publisher
241
240
  unless book.authors.empty?
242
- authors = entry.add_element('authors')
241
+ authors = entry.add_element("authors")
243
242
  book.authors.each do |author|
244
- authors.add_element('author').text = author
243
+ authors.add_element("author").text = author
245
244
  end
246
245
  end
247
- entry.add_element('read').text = book.redd.to_s if book.redd
248
- entry.add_element('loaned').text = book.loaned.to_s if book.loaned
249
- entry.add_element('rating').text = book.rating unless book.rating == Book::DEFAULT_RATING
250
- entry.add_element('comments').text = book.notes if book.notes && !book.notes.empty?
246
+ entry.add_element("read").text = book.redd.to_s if book.redd
247
+ entry.add_element("loaned").text = book.loaned.to_s if book.loaned
248
+ entry.add_element("rating").text = book.rating unless book.rating == Book::DEFAULT_RATING
249
+ entry.add_element("comments").text = book.notes if book.notes && !book.notes.empty?
251
250
  if File.exist?(cover(book))
252
- entry.add_element('cover').text = final_cover(book)
253
- image = images.add_element('image')
254
- image.add_attribute('id', final_cover(book))
251
+ entry.add_element("cover").text = final_cover(book)
252
+ image = images.add_element("image")
253
+ image.add_attribute("id", final_cover(book))
255
254
  image_s = ImageSize.new(IO.read(cover(book)))
256
- image.add_attribute('height', image_s.height.to_s)
257
- image.add_attribute('width', image_s.width.to_s)
258
- image.add_attribute('format', image_s.format)
255
+ image.add_attribute("height", image_s.height.to_s)
256
+ image.add_attribute("width", image_s.width.to_s)
257
+ image.add_attribute("format", image_s.format)
259
258
  end
260
259
  end
261
260
  doc
@@ -264,16 +263,16 @@ module Alexandria
264
263
  def xhtml_escape(str)
265
264
  escaped = str.dup
266
265
  # used to occasionally use CGI.escapeHTML
267
- escaped.gsub!(/&/, '&amp;')
268
- escaped.gsub!(/</, '&lt;')
269
- escaped.gsub!(/>/, '&gt;')
270
- escaped.gsub!(/\"/, '&quot;')
266
+ escaped.gsub!(/&/, "&amp;")
267
+ escaped.gsub!(/</, "&lt;")
268
+ escaped.gsub!(/>/, "&gt;")
269
+ escaped.gsub!(/\"/, "&quot;")
271
270
  escaped
272
271
  end
273
272
 
274
273
  def to_xhtml(css)
275
- generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
276
- xhtml = +''
274
+ generator = "Alexandria " + Alexandria::DISPLAY_VERSION
275
+ xhtml = +""
277
276
  xhtml << <<~EOS
278
277
  <?xml version="1.0" encoding="UTF-8"?>
279
278
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
@@ -326,7 +325,7 @@ module Alexandria
326
325
  <li class="book_author">#{xhtml_escape(author)}</li>
327
326
  EOS
328
327
  end
329
- xhtml << '</ul>'
328
+ xhtml << "</ul>"
330
329
  end
331
330
 
332
331
  unless book.edition.nil?
@@ -356,15 +355,15 @@ module Alexandria
356
355
  end
357
356
 
358
357
  def to_bibtex
359
- generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
360
- bibtex = +''
358
+ generator = "Alexandria " + Alexandria::DISPLAY_VERSION
359
+ bibtex = +""
361
360
  bibtex << "\%Generated on #{Date.today} by: #{generator}\n"
362
361
  bibtex << "\%\n"
363
362
  bibtex << "\n"
364
363
 
365
364
  auths = Hash.new(0)
366
365
  each do |book|
367
- k = (book.authors[0] || 'Anonymous').split[0]
366
+ k = (book.authors[0] || "Anonymous").split[0]
368
367
  if auths.key?(k)
369
368
  auths[k] += 1
370
369
  else
@@ -384,14 +383,14 @@ module Alexandria
384
383
  bibtex << "publisher = \"#{latex_escape(book.publisher)}\",\n"
385
384
  bibtex << "OPTnote = \"#{latex_escape(book.notes)}\",\n" if book.notes && !book.notes.empty?
386
385
  # year is a required field in bibtex @BOOK
387
- bibtex << 'year = ' + (book.publishing_year || '"n/a"').to_s + "\n"
386
+ bibtex << "year = " + (book.publishing_year || '"n/a"').to_s + "\n"
388
387
  bibtex << "}\n\n"
389
388
  end
390
389
  bibtex
391
390
  end
392
391
 
393
392
  def latex_escape(str)
394
- return '' if str.nil?
393
+ return "" if str.nil?
395
394
 
396
395
  my_str = str.dup
397
396
  my_str.gsub!(/%/, '\\%')