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
@@ -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
@@ -1,32 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2008 Joseph Method
3
+ # This file is part of Alexandria.
4
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.
14
- #
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
  module Alexandria
21
8
  def self.list_books_on_console(_title = true, authors = true)
22
- libraries_simpleton = Alexandria::Libraries.instance
23
- libraries_simpleton.reload
24
- libraries = Alexandria::Library.loadall
25
- output_string = ''
9
+ collection = Alexandria::LibraryCollection.instance
10
+ collection.reload
11
+ libraries = collection.all_regular_libraries
12
+ output_string = ""
26
13
  @books = libraries.flatten
27
14
  @books.each do |book|
28
- book_authors = book.authors.join(' & ') if authors
29
- 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"
30
17
  end
31
18
  output_string
32
19
  end
@@ -0,0 +1,37 @@
1
+ # This file is automatically generated by the alexandria installer.
2
+ # Do not edit it directly.
3
+
4
+ module Alexandria
5
+ class Preferences
6
+ DEFAULT_VALUES = {
7
+ "position" => [0, 0],
8
+ "size" => [640, 480],
9
+ "maximized" => false,
10
+ "sidepane_position" => 140,
11
+ "view_as" => 0,
12
+ "arrange_icons_mode" => 0,
13
+ "reverse_icons" => false,
14
+ "selected_library" => "",
15
+ "barcode_scanner" => "CueCat",
16
+ "play_scanning_sound" => true,
17
+ "play_scan_sound" => true,
18
+ "toolbar_visible" => true,
19
+ "sidepane_visible" => true,
20
+ "statusbar_visible" => true,
21
+ "col_authors_visible" => true,
22
+ "col_edition_visible" => true,
23
+ "col_isbn_visible" => true,
24
+ "col_publisher_visible" => true,
25
+ "col_publish_date_visible" => true,
26
+ "col_loaned_to_visible" => true,
27
+ "col_rating_visible" => true,
28
+ "col_redd_visible" => true,
29
+ "col_own_visible" => true,
30
+ "col_want_visible" => true,
31
+ "col_tags_visible" => true,
32
+ "cols_width" => "{}",
33
+ "providers_priority" => ["Amazon", "BarnesAndNoble", "AdLibris", "Proxis", "Thalia", "Siciliano", "WorldCat", "LOC", "BL", "SBN"],
34
+ "view_advanced_settings" => false
35
+ }
36
+ end
37
+ end
@@ -41,7 +41,7 @@ module Alexandria
41
41
 
42
42
  def self.current
43
43
  @@current_queue
44
- rescue
44
+ rescue StandardError
45
45
  nil
46
46
  end
47
47
 
@@ -60,12 +60,14 @@ module Alexandria
60
60
  break @pending_calls.pop
61
61
  end
62
62
  return if ary.nil?
63
+
63
64
  id, procedure, args, need_retval = ary
64
65
  retval = procedure.call(*args)
65
- if need_retval
66
- @protect_pending_retvals.synchronize do
67
- @pending_retvals << [id, retval]
68
- end
66
+
67
+ return unless need_retval
68
+
69
+ @protect_pending_retvals.synchronize do
70
+ @pending_retvals << [id, retval]
69
71
  end
70
72
  end
71
73
 
@@ -80,14 +82,14 @@ module Alexandria
80
82
  @id += 1
81
83
  @pending_calls << [@id, procedure, args, need_retval]
82
84
  end
83
- if need_retval
84
- loop do
85
- @protect_pending_retvals.synchronize do
86
- ary = @pending_retvals.find { |id, _retval| id == @id }
87
- if ary
88
- @pending_retvals.delete(ary)
89
- return ary[1]
90
- end
85
+ return unless need_retval
86
+
87
+ loop do
88
+ @protect_pending_retvals.synchronize do
89
+ ary = @pending_retvals.find { |id, _retval| id == @id }
90
+ if ary
91
+ @pending_retvals.delete(ary)
92
+ return ary[1]
91
93
  end
92
94
  end
93
95
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
4
+ #
5
+ # See the file README.md for authorship and licensing information.
6
+
7
+ module Alexandria
8
+ class ExportFormat
9
+ attr_reader :name, :ext, :message
10
+
11
+ include GetText
12
+ include Logging
13
+ extend GetText
14
+ bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
15
+
16
+ def self.all
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)
25
+ ]
26
+ end
27
+
28
+ def invoke(library, sort_order, filename, *args)
29
+ sorted = ExportLibrary.new(library, sort_order)
30
+ log.debug { "Exporting library sorted by #{sort_order}" }
31
+ sorted.send(@message, filename, *args)
32
+ end
33
+
34
+ def needs_preview?
35
+ @needs_preview
36
+ end
37
+
38
+ private
39
+
40
+ def initialize(name, ext, message, needs_preview = false)
41
+ @name = name
42
+ @ext = ext
43
+ @message = message
44
+ @needs_preview = needs_preview
45
+ end
46
+ end
47
+ end
@@ -1,77 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2004-2006 Laurent Sansonetti
4
- # Copyright (C) 2007 Cathal Mc Ginley
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.
21
-
22
- # Export sorting added 23 Oct 2007 by Cathal Mc Ginley
23
- # Classes LibrarySortOrder and SortedLibrary, and changed ExportFormat#invoke
24
- # iPod Notes support added 20 January 2008 by Tim Malone
25
- # require 'cgi'
5
+ # See the file README.md for authorship and licensing information.
26
6
 
27
- require 'csv'
28
- require 'image_size'
7
+ require "csv"
8
+ require "image_size"
9
+ require "tmpdir"
29
10
 
30
11
  module Alexandria
31
- class LibrarySortOrder
32
- include Logging
33
-
34
- def initialize(book_attribute, ascending = true)
35
- @book_attribute = book_attribute
36
- @ascending = ascending
37
- end
38
-
39
- def sort(library)
40
- sorted = library.sort_by do |book|
41
- book.send(@book_attribute)
42
- end
43
- sorted.reverse! unless @ascending
44
- sorted
45
- rescue => ex
46
- log.warn { "Could not sort library by #{@book_attribute.inspect}: #{ex.message}" }
47
- library
48
- end
49
-
50
- def to_s
51
- "#{@book_attribute} #{@ascending ? '(ascending)' : '(descending)'}"
52
- end
53
-
54
- class Unsorted < LibrarySortOrder
55
- def initialize; end
56
-
57
- def sort(library)
58
- library
59
- end
60
-
61
- def to_s
62
- 'default order'
63
- end
64
- end
65
- end
66
-
67
- class SortedLibrary < Library
12
+ class ExportLibrary
68
13
  def initialize(library, sort_order)
69
- super(library.name)
70
14
  @library = library
71
- sorted = sort_order.sort(library)
72
- sorted.each do |book|
73
- self << book
74
- end
15
+ @sorted = sort_order.sort(library)
75
16
  end
76
17
 
77
18
  def cover(book)
@@ -85,89 +26,48 @@ module Alexandria
85
26
  def copy_covers(dest)
86
27
  @library.copy_covers(dest)
87
28
  end
88
- end
89
-
90
- class ExportFormat
91
- attr_reader :name, :ext, :message
92
-
93
- include GetText
94
- include Logging
95
- extend GetText
96
- bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
97
-
98
- def self.all
99
- [
100
- new(_('Archived ONIX XML'), 'onix.tbz2', :export_as_onix_xml_archive),
101
- new(_('Archived Tellico XML'), 'tc', :export_as_tellico_xml_archive),
102
- new(_('BibTeX'), 'bib', :export_as_bibtex),
103
- new(_('CSV list'), 'csv', :export_as_csv_list),
104
- new(_('ISBN List'), 'txt', :export_as_isbn_list),
105
- new(_('iPod Notes'), nil, :export_as_ipod_notes),
106
- new(_('HTML Web Page'), nil, :export_as_html, true)
107
- ]
108
- end
109
-
110
- def invoke(library, sort_order, filename, *args)
111
- if sort_order
112
- sorted = SortedLibrary.new(library, sort_order)
113
- log.debug { "Exporting library sorted by #{sort_order}" }
114
- sorted.send(@message, filename, *args)
115
- else
116
- library.send(@message, filename, *args)
117
- end
118
- end
119
29
 
120
- def needs_preview?
121
- @needs_preview
30
+ def name
31
+ @library.name
122
32
  end
123
33
 
124
- private
125
-
126
- def initialize(name, ext, message, needs_preview = false)
127
- @name = name
128
- @ext = ext
129
- @message = message
130
- @needs_preview = needs_preview
34
+ def each(&block)
35
+ @sorted.each(&block)
131
36
  end
132
- end
133
37
 
134
- module Exportable
135
38
  def export_as_onix_xml_archive(filename)
136
- File.open(File.join(Dir.tmpdir, 'onix.xml'), 'w') do |io|
39
+ dir = Dir.mktmpdir
40
+ File.open(File.join(dir, "onix.xml"), "w") do |io|
137
41
  to_onix_document.write(io, 0)
138
42
  end
139
- copy_covers(File.join(Dir.tmpdir, 'images'))
140
- Dir.chdir(Dir.tmpdir) do
43
+ copy_covers(File.join(dir, "images"))
44
+ Dir.chdir(dir) do
141
45
  output = `tar -cjf \"#{filename}\" onix.xml images 2>&1`
142
46
  raise output unless $CHILD_STATUS.success?
143
47
  end
144
- FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
145
- FileUtils.rm(File.join(Dir.tmpdir, 'onix.xml'))
48
+ FileUtils.rm_rf(File.join(dir, "images"))
49
+ FileUtils.rm(File.join(dir, "onix.xml"))
50
+ ensure
51
+ FileUtils.remove_entry dir
146
52
  end
147
53
 
148
54
  def export_as_tellico_xml_archive(filename)
149
- File.open(File.join(Dir.tmpdir, 'tellico.xml'), 'w') do |io|
150
- begin
151
- to_tellico_document.write(io, 0)
152
- rescue => ex
153
- puts ex.message
154
- puts ex.backtrace
155
- raise ex
156
- end
55
+ File.open(File.join(Dir.tmpdir, "tellico.xml"), "w") do |io|
56
+ to_tellico_document.write(io, 0)
157
57
  end
158
- copy_covers(File.join(Dir.tmpdir, 'images'))
58
+ copy_covers(File.join(Dir.tmpdir, "images"))
159
59
  Dir.chdir(Dir.tmpdir) do
160
60
  output = `zip -q -r \"#{filename}\" tellico.xml images 2>&1`
161
61
  raise output unless $CHILD_STATUS.success?
162
62
  end
163
- FileUtils.rm_rf(File.join(Dir.tmpdir, 'images'))
164
- FileUtils.rm(File.join(Dir.tmpdir, 'tellico.xml'))
63
+ FileUtils.rm_rf(File.join(Dir.tmpdir, "images"))
64
+ FileUtils.rm(File.join(Dir.tmpdir, "tellico.xml"))
165
65
  end
166
66
 
167
67
  def export_as_isbn_list(filename)
168
- File.open(filename, 'w') do |io|
68
+ File.open(filename, "w") do |io|
169
69
  each do |book|
170
- io.puts((book.isbn || ''))
70
+ io.puts((book.isbn || ""))
171
71
  end
172
72
  end
173
73
  end
@@ -175,17 +75,17 @@ module Alexandria
175
75
  def export_as_html(filename, theme)
176
76
  FileUtils.mkdir(filename) unless File.exist?(filename)
177
77
  Dir.chdir(filename) do
178
- copy_covers('pixmaps')
179
- FileUtils.cp_r(theme.pixmaps_directory, 'pixmaps') if theme.has_pixmaps?
180
- FileUtils.cp(theme.css_file, '.')
181
- File.open('index.html', 'w') do |io|
78
+ copy_covers("pixmaps")
79
+ FileUtils.cp_r(theme.pixmaps_directory, "pixmaps") if theme.has_pixmaps?
80
+ FileUtils.cp(theme.css_file, ".")
81
+ File.open("index.html", "w") do |io|
182
82
  io << to_xhtml(File.basename(theme.css_file))
183
83
  end
184
84
  end
185
85
  end
186
86
 
187
87
  def export_as_bibtex(filename)
188
- File.open(filename, 'w') do |io|
88
+ File.open(filename, "w") do |io|
189
89
  io << to_bibtex
190
90
  end
191
91
  end
@@ -194,27 +94,28 @@ module Alexandria
194
94
  FileUtils.mkdir(filename) unless File.exist?(filename)
195
95
  tempdir = Dir.getwd
196
96
  Dir.chdir(filename)
197
- copy_covers('pixmaps')
198
- File.open('index.linx', 'w') do |io|
199
- io.puts '<TITLE>' + name + '</TITLE>'
97
+ copy_covers("pixmaps")
98
+ File.open("index.linx", "w") do |io|
99
+ io.puts "<TITLE>" + name + "</TITLE>"
200
100
  each do |book|
201
- io.puts '<A HREF="' + book.ident + '">' + book.title + '</A>'
101
+ io.puts '<A HREF="' + book.ident + '">' + book.title + "</A>"
202
102
  end
203
103
  io.close
204
104
  end
205
105
  each do |book|
206
- File.open(book.ident, 'w') do |io|
106
+ File.open(book.ident, "w") do |io|
207
107
  io.puts "<TITLE>#{book.title} </TITLE>"
208
108
  # put a link to the book's cover. only works on iPod 5G and above(?).
209
109
  if File.exist?(cover(book))
210
- io.puts '<A HREF="pixmaps/' + book.ident + '.jpg' + '">' + book.title + '</A>'
110
+ io.puts '<A HREF="pixmaps/' + book.ident + ".jpg" + '">' + book.title + "</A>"
211
111
  else
212
112
  io.puts book.title
213
113
  end
214
- io.puts book.authors.join(', ')
114
+ io.puts book.authors.join(", ")
215
115
  io.puts book.edition
216
- io.puts((book.isbn || ''))
217
- # we need to close the files so the iPod can be ejected/unmounted without us closing Alexandria
116
+ io.puts((book.isbn || ""))
117
+ # we need to close the files so the iPod can be ejected/unmounted
118
+ # without us closing Alexandria
218
119
  io.close
219
120
  end
220
121
  end
@@ -223,84 +124,83 @@ module Alexandria
223
124
  end
224
125
 
225
126
  def export_as_csv_list(filename)
226
- CSV.open(filename, 'w', col_sep: ';') do |csv|
227
- csv << ['Title', 'Authors', 'Publisher', 'Edition', 'ISBN', 'Year Published',
228
- "Rating(#{Book::DEFAULT_RATING} to #{Book::MAX_RATING_STARS})", 'Notes',
229
- 'Want?', 'Read?', 'Own?', 'Tags']
127
+ CSV.open(filename, "w", col_sep: ";") do |csv|
128
+ csv << ["Title", "Authors", "Publisher", "Edition", "ISBN", "Year Published",
129
+ "Rating(#{Book::DEFAULT_RATING} to #{Book::MAX_RATING_STARS})", "Notes",
130
+ "Want?", "Read?", "Own?", "Tags"]
230
131
  each do |book|
231
- csv << [book.title, book.authors.join(', '), book.publisher, book.edition, book.isbn,
232
- book.publishing_year, book.rating, book.notes,
233
- (book.want ? '1' : '0'), (book.redd ? '1' : '0'), (book.own ? '1' : '0'),
234
- (book.tags ? book.tags.join(', ') : '')]
132
+ csv << [book.title, book.authors.join(", "), book.publisher, book.edition,
133
+ book.isbn, book.publishing_year, book.rating, book.notes,
134
+ (book.want ? "1" : "0"), (book.redd ? "1" : "0"), (book.own ? "1" : "0"),
135
+ (book.tags ? book.tags.join(", ") : "")]
235
136
  end
236
137
  end
237
138
  end
238
139
 
239
140
  private
240
141
 
241
- ONIX_DTD_URL = 'http://www.editeur.org/onix/2.1/reference/onix-international.dtd'
142
+ ONIX_DTD_URL = "http://www.editeur.org/onix/2.1/reference/onix-international.dtd"
242
143
  def to_onix_document
243
144
  doc = REXML::Document.new
244
145
  doc << REXML::XMLDecl.new
245
- doc << REXML::DocType.new('ONIXMessage',
146
+ doc << REXML::DocType.new("ONIXMessage",
246
147
  "SYSTEM \"#{ONIX_DTD_URL}\"")
247
- msg = doc.add_element('ONIXMessage')
248
- header = msg.add_element('Header')
249
- header.add_element('FromCompany').text = 'Alexandria'
250
- header.add_element('FromPerson').text = Etc.getlogin
148
+ msg = doc.add_element("ONIXMessage")
149
+ header = msg.add_element("Header")
150
+ header.add_element("FromCompany").text = "Alexandria"
151
+ header.add_element("FromPerson").text = Etc.getlogin
251
152
  now = Time.now
252
- header.add_element('SentDate').text = format('%.4d%.2d%.2d%.2d%.2d',
253
- now.year, now.month, now.day, now.hour, now.min)
254
- header.add_element('MessageNote').text = name
255
- each_with_index do |book, idx|
153
+ header.add_element("SentDate").text = now.strftime("%Y%m%d%H%M")
154
+ header.add_element("MessageNote").text = name
155
+ @sorted.each_with_index do |book, idx|
256
156
  # fields that are missing: edition and rating.
257
- prod = msg.add_element('Product')
258
- prod.add_element('RecordReference').text = idx
259
- prod.add_element('NotificationType').text = '03' # confirmed
260
- prod.add_element('RecordSourceName').text =
261
- 'Alexandria ' + Alexandria::DISPLAY_VERSION
262
- prod.add_element('ISBN').text = (book.isbn || '')
263
- prod.add_element('ProductForm').text = 'BA' # book
264
- prod.add_element('DistinctiveTitle').text = book.title
157
+ prod = msg.add_element("Product")
158
+ prod.add_element("RecordReference").text = idx
159
+ prod.add_element("NotificationType").text = "03" # confirmed
160
+ prod.add_element("RecordSourceName").text =
161
+ "Alexandria " + Alexandria::DISPLAY_VERSION
162
+ prod.add_element("ISBN").text = (book.isbn || "")
163
+ prod.add_element("ProductForm").text = "BA" # book
164
+ prod.add_element("DistinctiveTitle").text = book.title
265
165
  unless book.authors.empty?
266
166
  book.authors.each do |author|
267
- elem = prod.add_element('Contributor')
167
+ elem = prod.add_element("Contributor")
268
168
  # author
269
- elem.add_element('ContributorRole').text = 'A01'
270
- elem.add_element('PersonName').text = author
169
+ elem.add_element("ContributorRole").text = "A01"
170
+ elem.add_element("PersonName").text = author
271
171
  end
272
172
  end
273
173
  if book.notes && !book.notes.empty?
274
- elem = prod.add_element('OtherText')
174
+ elem = prod.add_element("OtherText")
275
175
  # reader description
276
- elem.add_element('TextTypeCode').text = '12'
277
- elem.add_element('TextFormat').text = '00' # ASCII
278
- elem.add_element('Text').text = book.notes
176
+ elem.add_element("TextTypeCode").text = "12"
177
+ elem.add_element("TextFormat").text = "00" # ASCII
178
+ elem.add_element("Text").text = book.notes
279
179
  end
280
180
  if File.exist?(cover(book))
281
- elem = prod.add_element('MediaFile')
181
+ elem = prod.add_element("MediaFile")
282
182
  # front cover image
283
- elem.add_element('MediaFileTypeCode').text = '04'
284
- elem.add_element('MediaFileFormatCode').text =
285
- (Library.jpeg?(cover(book)) ? '03' : '02')
183
+ elem.add_element("MediaFileTypeCode").text = "04"
184
+ elem.add_element("MediaFileFormatCode").text =
185
+ (Library.jpeg?(cover(book)) ? "03" : "02")
286
186
  # filename
287
- elem.add_element('MediaFileLinkTypeCode').text = '06'
288
- elem.add_element('MediaFileLink').text =
289
- File.join('images', final_cover(book))
187
+ elem.add_element("MediaFileLinkTypeCode").text = "06"
188
+ elem.add_element("MediaFileLink").text =
189
+ File.join("images", final_cover(book))
290
190
  end
291
191
  if book.isbn
292
- BookProviders.each do |provider|
293
- elem = prod.add_element('ProductWebsite')
294
- elem.add_element('ProductWebsiteDescription').text =
192
+ BookProviders.list.each do |provider|
193
+ elem = prod.add_element("ProductWebsite")
194
+ elem.add_element("ProductWebsiteDescription").text =
295
195
  provider.fullname
296
- elem.add_element('ProductWebsiteLink').text =
196
+ elem.add_element("ProductWebsiteLink").text =
297
197
  provider.url(book)
298
198
  end
299
199
  end
300
- elem = prod.add_element('Publisher')
301
- elem.add_element('PublishingRole').text = '01'
302
- elem.add_element('PublisherName').text = book.publisher
303
- prod.add_element('PublicationDate').text = book.publishing_year
200
+ elem = prod.add_element("Publisher")
201
+ elem.add_element("PublishingRole").text = "01"
202
+ elem.add_element("PublisherName").text = book.publisher
203
+ prod.add_element("PublicationDate").text = book.publishing_year
304
204
  end
305
205
  doc
306
206
  end
@@ -310,49 +210,51 @@ module Alexandria
310
210
  # http://periapsis.org/tellico/doc/hacking.html
311
211
  doc = REXML::Document.new
312
212
  doc << REXML::XMLDecl.new
313
- doc << REXML::DocType.new('tellico',
213
+ doc << REXML::DocType.new("tellico",
314
214
  'PUBLIC "-//Robby Stephenson/DTD Tellico V7.0//EN"' \
315
215
  ' "http://periapsis.org/tellico/dtd/v7/tellico.dtd"')
316
- tellico = doc.add_element('tellico')
317
- tellico.add_attribute('syntaxVersion', '7')
318
- tellico.add_namespace('http://periapsis.org/tellico/')
319
- collection = tellico.add_element('collection')
320
- collection.add_attribute('title', name)
321
- collection.add_attribute('type', '2')
322
- fields = collection.add_element('fields')
323
- field1 = fields.add_element('field')
216
+ tellico = doc.add_element("tellico")
217
+ tellico.add_attribute("syntaxVersion", "7")
218
+ tellico.add_namespace("http://periapsis.org/tellico/")
219
+ collection = tellico.add_element("collection")
220
+ collection.add_attribute("title", name)
221
+ collection.add_attribute("type", "2")
222
+ fields = collection.add_element("fields")
223
+ field1 = fields.add_element("field")
324
224
  # a field named _default implies adding all default book
325
225
  # collection fields
326
- field1.add_attribute('name', '_default')
327
- images = collection.add_element('images')
328
- each_with_index do |book, idx|
329
- entry = collection.add_element('entry')
226
+ field1.add_attribute("name", "_default")
227
+ images = collection.add_element("images")
228
+ @sorted.each_with_index do |book, idx|
229
+ entry = collection.add_element("entry")
330
230
  new_index = (idx + 1).to_s
331
- entry.add_attribute('id', new_index)
231
+ entry.add_attribute("id", new_index)
332
232
  # translate the binding
333
- entry.add_element('title').text = book.title
334
- entry.add_element('isbn').text = (book.isbn || '')
335
- entry.add_element('pub_year').text = book.publishing_year
336
- entry.add_element('binding').text = book.edition
337
- entry.add_element('publisher').text = book.publisher
233
+ entry.add_element("title").text = book.title
234
+ entry.add_element("isbn").text = (book.isbn || "")
235
+ entry.add_element("pub_year").text = book.publishing_year
236
+ entry.add_element("binding").text = book.edition
237
+ entry.add_element("publisher").text = book.publisher
338
238
  unless book.authors.empty?
339
- authors = entry.add_element('authors')
239
+ authors = entry.add_element("authors")
340
240
  book.authors.each do |author|
341
- authors.add_element('author').text = author
241
+ authors.add_element("author").text = author
342
242
  end
343
243
  end
344
- entry.add_element('read').text = book.redd.to_s if book.redd
345
- entry.add_element('loaned').text = book.loaned.to_s if book.loaned
346
- entry.add_element('rating').text = book.rating unless book.rating == Book::DEFAULT_RATING
347
- entry.add_element('comments').text = book.notes if book.notes && !book.notes.empty?
244
+ entry.add_element("read").text = book.redd.to_s if book.redd
245
+ entry.add_element("loaned").text = book.loaned.to_s if book.loaned
246
+ unless book.rating == Book::DEFAULT_RATING
247
+ entry.add_element("rating").text = book.rating
248
+ end
249
+ entry.add_element("comments").text = book.notes if book.notes && !book.notes.empty?
348
250
  if File.exist?(cover(book))
349
- entry.add_element('cover').text = final_cover(book)
350
- image = images.add_element('image')
351
- 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))
352
254
  image_s = ImageSize.new(IO.read(cover(book)))
353
- image.add_attribute('height', image_s.get_height.to_s)
354
- image.add_attribute('width', image_s.get_width.to_s)
355
- image.add_attribute('format', image_s.get_type)
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)
356
258
  end
357
259
  end
358
260
  doc
@@ -361,111 +263,107 @@ module Alexandria
361
263
  def xhtml_escape(str)
362
264
  escaped = str.dup
363
265
  # used to occasionally use CGI.escapeHTML
364
- escaped.gsub!(/&/, '&amp;')
365
- escaped.gsub!(/</, '&lt;')
366
- escaped.gsub!(/>/, '&gt;')
367
- escaped.gsub!(/\"/, '&quot;')
266
+ escaped.gsub!(/&/, "&amp;")
267
+ escaped.gsub!(/</, "&lt;")
268
+ escaped.gsub!(/>/, "&gt;")
269
+ escaped.gsub!(/"/, "&quot;")
368
270
  escaped
369
271
  end
370
272
 
371
273
  def to_xhtml(css)
372
- generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
373
- xhtml = ''
374
- xhtml << <<EOS
375
- <?xml version="1.0" encoding="UTF-8"?>
376
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
377
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
378
- <html>
379
- <head>
380
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
381
- <meta name="Author" content="#{Etc.getlogin}"/>
382
- <meta name="Description" content="List of books"/>
383
- <meta name="Keywords" content="books"/>
384
- <meta name="Generator" content="#{xhtml_escape(generator)}"/>
385
- <title>#{xhtml_escape(name)}</title>
386
- <link rel="stylesheet" href="#{xhtml_escape(css)}" type="text/css"/>
387
- </head>
388
- <body>
389
- <h1 class="library_name">#{xhtml_escape(name)}</h1>
390
- EOS
274
+ generator = "Alexandria " + Alexandria::DISPLAY_VERSION
275
+ xhtml = +""
276
+ xhtml << <<~EOS
277
+ <?xml version="1.0" encoding="UTF-8"?>
278
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
279
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
280
+ <html>
281
+ <head>
282
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
283
+ <meta name="Author" content="#{Etc.getlogin}"/>
284
+ <meta name="Description" content="List of books"/>
285
+ <meta name="Keywords" content="books"/>
286
+ <meta name="Generator" content="#{xhtml_escape(generator)}"/>
287
+ <title>#{xhtml_escape(name)}</title>
288
+ <link rel="stylesheet" href="#{xhtml_escape(css)}" type="text/css"/>
289
+ </head>
290
+ <body>
291
+ <h1 class="library_name">#{xhtml_escape(name)}</h1>
292
+ EOS
391
293
 
392
294
  each do |book|
393
- xhtml << <<EOS
394
- <div class="book">
395
- <p class="book_isbn">#{book.isbn}</p>
396
- EOS
295
+ xhtml << <<~EOS
296
+ <div class="book">
297
+ <p class="book_isbn">#{book.isbn}</p>
298
+ EOS
397
299
 
398
300
  if File.exist?(cover(book))
399
- xhtml << <<EOS
400
- <img class="book_cover"
401
- src="#{File.join('pixmaps', final_cover(book))}"
402
- alt="Cover file for '#{xhtml_escape(book.title)}'"
403
- EOS
404
301
  image_s = ImageSize.new(IO.read(cover(book)))
405
- xhtml << <<EOS
406
- height="#{image_s.get_height}" width="#{image_s.get_width}"
407
- EOS
408
- xhtml << <<EOS
409
- />
410
- EOS
302
+ xhtml << <<~EOS
303
+ <img class="book_cover"
304
+ src="#{File.join('pixmaps', final_cover(book))}"
305
+ alt="Cover file for '#{xhtml_escape(book.title)}'"
306
+ height="#{image_s.height}" width="#{image_s.width}"
307
+ />
308
+ EOS
411
309
  else
412
- xhtml << <<EOS
413
- <div class="no_book_cover"></div>
414
- EOS
310
+ xhtml << <<~EOS
311
+ <div class="no_book_cover"></div>
312
+ EOS
415
313
  end
416
314
 
417
315
  unless book.title.nil?
418
- xhtml << <<EOS
419
- <p class="book_title">#{xhtml_escape(book.title)}</p>
420
- EOS
316
+ xhtml << <<~EOS
317
+ <p class="book_title">#{xhtml_escape(book.title)}</p>
318
+ EOS
421
319
  end
422
320
 
423
321
  unless book.authors.empty?
424
322
  xhtml << '<ul class="book_authors">'
425
323
  book.authors.each do |author|
426
- xhtml << <<EOS
427
- <li class="book_author">#{xhtml_escape(author)}</li>
428
- EOS
324
+ xhtml << <<~EOS
325
+ <li class="book_author">#{xhtml_escape(author)}</li>
326
+ EOS
429
327
  end
430
- xhtml << '</ul>'
328
+ xhtml << "</ul>"
431
329
  end
432
330
 
433
331
  unless book.edition.nil?
434
- xhtml << <<EOS
435
- <p class="book_binding">#{xhtml_escape(book.edition)}</p>
436
- EOS
332
+ xhtml << <<~EOS
333
+ <p class="book_binding">#{xhtml_escape(book.edition)}</p>
334
+ EOS
437
335
  end
438
336
 
439
337
  unless book.publisher.nil?
440
- xhtml << <<EOS
441
- <p class="book_publisher">#{xhtml_escape(book.publisher)}</p>
442
- EOS
338
+ xhtml << <<~EOS
339
+ <p class="book_publisher">#{xhtml_escape(book.publisher)}</p>
340
+ EOS
443
341
  end
444
342
 
445
- xhtml << <<EOS
446
- </div>
447
- EOS
343
+ xhtml << <<~EOS
344
+ </div>
345
+ EOS
448
346
  end
449
- xhtml << <<EOS
450
- <p class="copyright">
451
- Generated on #{xhtml_escape(Date.today.to_s)}
452
- by <a href="#{xhtml_escape(Alexandria::WEBSITE_URL)}">#{xhtml_escape(generator)}</a>.
453
- </p>
454
- </body>
455
- </html>
456
- EOS
347
+ xhtml << <<~EOS
348
+ <p class="copyright">
349
+ Generated on #{xhtml_escape(Date.today.to_s)}
350
+ by <a href="#{xhtml_escape(Alexandria::WEBSITE_URL)}">#{xhtml_escape(generator)}</a>.
351
+ </p>
352
+ </body>
353
+ </html>
354
+ EOS
457
355
  end
458
356
 
459
357
  def to_bibtex
460
- generator = 'Alexandria ' + Alexandria::DISPLAY_VERSION
461
- bibtex = ''
358
+ generator = "Alexandria " + Alexandria::DISPLAY_VERSION
359
+ bibtex = +""
462
360
  bibtex << "\%Generated on #{Date.today} by: #{generator}\n"
463
361
  bibtex << "\%\n"
464
362
  bibtex << "\n"
465
363
 
466
364
  auths = Hash.new(0)
467
365
  each do |book|
468
- k = (book.authors[0] || 'Anonymous').split[0]
366
+ k = (book.authors[0] || "Anonymous").split[0]
469
367
  if auths.key?(k)
470
368
  auths[k] += 1
471
369
  else
@@ -483,35 +381,30 @@ EOS
483
381
  bibtex << "\",\n"
484
382
  bibtex << "title = \"#{latex_escape(book.title)}\",\n"
485
383
  bibtex << "publisher = \"#{latex_escape(book.publisher)}\",\n"
486
- bibtex << "OPTnote = \"#{latex_escape(book.notes)}\",\n" if book.notes && !book.notes.empty?
384
+ if book.notes && !book.notes.empty?
385
+ bibtex << "OPTnote = \"#{latex_escape(book.notes)}\",\n"
386
+ end
487
387
  # year is a required field in bibtex @BOOK
488
- bibtex << 'year = ' + (book.publishing_year || '"n/a"').to_s + "\n"
388
+ bibtex << "year = " + (book.publishing_year || '"n/a"').to_s + "\n"
489
389
  bibtex << "}\n\n"
490
390
  end
491
391
  bibtex
492
392
  end
493
393
 
494
394
  def latex_escape(str)
495
- return '' if str.nil?
395
+ return "" if str.nil?
396
+
496
397
  my_str = str.dup
497
398
  my_str.gsub!(/%/, '\\%')
498
399
  my_str.gsub!(/~/, '\\textasciitilde')
499
- my_str.gsub!(/\&/, '\\\\&')
400
+ my_str.gsub!(/&/, '\\\\&')
500
401
  my_str.gsub!(/\#/, '\\\\#')
501
402
  my_str.gsub!(/\{/, '\\{')
502
403
  my_str.gsub!(/\}/, '\\}')
503
404
  my_str.gsub!(/_/, '\\_')
504
405
  my_str.gsub!(/\$/, "\\\$")
505
- my_str.gsub!(/\"(.+)\"/, "``\1''")
406
+ my_str.gsub!(/"(.+)"/, "``\1''")
506
407
  my_str
507
408
  end
508
409
  end
509
-
510
- class Library
511
- include Exportable
512
- end
513
-
514
- class SmartLibrary
515
- include Exportable
516
- end
517
410
  end