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
@@ -28,24 +28,24 @@
28
28
 
29
29
  # NOTE: this modified version is based on the Alexandria WorldCat provider.
30
30
 
31
- require 'cgi'
32
- require 'alexandria/net'
33
- require 'alexandria/book_providers/web'
31
+ require "cgi"
32
+ require "alexandria/net"
33
+ require "alexandria/book_providers/web"
34
34
 
35
35
  module Alexandria
36
36
  class BookProviders
37
37
  class BarnesAndNobleProvider < WebsiteBasedProvider
38
- include Alexandria::Logging
38
+ include Logging
39
39
 
40
- SITE = 'http://www.barnesandnoble.com'
40
+ SITE = "http://www.barnesandnoble.com"
41
41
 
42
- BASE_ISBN_SEARCH_URL = 'http://www.barnesandnoble.com/s/%s'
42
+ BASE_ISBN_SEARCH_URL = "http://www.barnesandnoble.com/s/%s"
43
43
 
44
- BASE_SEARCH_URL = 'http://search.barnesandnoble.com/booksearch' \
45
- '/results.asp?%s=%s' # type, term
44
+ BASE_SEARCH_URL = "http://search.barnesandnoble.com/booksearch" \
45
+ "/results.asp?%s=%s" # type, term
46
46
 
47
47
  def initialize
48
- super('BarnesAndNoble', 'BarnesAndNoble')
48
+ super("BarnesAndNoble", "BarnesAndNoble")
49
49
  @agent = nil
50
50
  prefs.read
51
51
  end
@@ -56,7 +56,8 @@ module Alexandria
56
56
  end
57
57
 
58
58
  def fetch_redirectly(uri_str, limit = 5)
59
- raise NoResultsError, 'HTTP redirect too deep' if limit.zero?
59
+ raise NoResultsError, _("HTTP redirect too deep") if limit.zero?
60
+
60
61
  if limit < 10
61
62
  sleep 0.1
62
63
  log.debug { "Redirectly :: #{uri_str}" }
@@ -66,9 +67,9 @@ module Alexandria
66
67
  response = agent.get(uri_str)
67
68
  log.debug { response.inspect }
68
69
  case response
69
- when Net::HTTPSuccess then response
70
- when Net::HTTPRedirection then
71
- redirect = URI.parse response['Location']
70
+ when Net::HTTPSuccess then response
71
+ when Net::HTTPRedirection
72
+ redirect = URI.parse response["Location"]
72
73
  redirect = URI.parse(uri_str) + redirect if redirect.relative?
73
74
  fetch_redirectly(redirect.to_s, (limit - 1))
74
75
  else
@@ -78,7 +79,7 @@ module Alexandria
78
79
 
79
80
  def search(criterion, type)
80
81
  req = create_search_uri(type, criterion)
81
- puts "Requesting #{req}" if $DEBUG
82
+ log.debug { "Requesting #{req}" }
82
83
  html_data = fetch_redirectly(req)
83
84
 
84
85
  if type == SEARCH_BY_ISBN
@@ -93,17 +94,17 @@ module Alexandria
93
94
 
94
95
  def url(book)
95
96
  create_search_uri(SEARCH_BY_ISBN, book.isbn)
96
- rescue => ex
97
+ rescue StandardError => ex
97
98
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
98
99
  nil
99
100
  end
100
101
 
101
102
  def create_search_uri(search_type, search_term)
102
103
  (search_type_code = {
103
- SEARCH_BY_AUTHORS => 'ATH',
104
- SEARCH_BY_TITLE => 'TTL',
105
- SEARCH_BY_KEYWORD => 'WRD' # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
106
- }[search_type]) || ''
104
+ SEARCH_BY_AUTHORS => "ATH",
105
+ SEARCH_BY_TITLE => "TTL",
106
+ SEARCH_BY_KEYWORD => "WRD" # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
107
+ }[search_type]) || ""
107
108
  if search_type == SEARCH_BY_ISBN
108
109
  BASE_ISBN_SEARCH_URL % Library.canonicalise_ean(search_term) # isbn-13
109
110
  else
@@ -127,19 +128,19 @@ module Alexandria
127
128
  result = {}
128
129
  # img = div % 'div.book-image/a/img'
129
130
  # result[:image_url] = img['src'] if img
130
- title_header = div % 'h2'
131
- title_links = title_header / 'a'
131
+ title_header = div % "h2"
132
+ title_links = title_header / "a"
132
133
  result[:title] = title_links.first.inner_text
133
- result[:url] = title_links.first['href']
134
+ result[:url] = title_links.first["href"]
134
135
 
135
136
  book_search_results << result
136
137
  end
137
- rescue => ex
138
+ rescue StandardError => ex
138
139
  trace = ex.backtrace.join("\n> ")
139
- log.warn {
140
- 'Failed parsing search results for Barnes & Noble ' \
140
+ log.warn do
141
+ "Failed parsing search results for Barnes & Noble " \
141
142
  "#{ex.message} #{trace}"
142
- }
143
+ end
143
144
  end
144
145
  book_search_results
145
146
  end
@@ -149,8 +150,8 @@ module Alexandria
149
150
  begin
150
151
  book_data = {}
151
152
 
152
- dl = (doc / 'dl').first
153
- dts = dl.children_of_type('dt')
153
+ dl = (doc / "dl").first
154
+ dts = dl.children_of_type("dt")
154
155
  dts.each do |dt|
155
156
  value = dt.next_sibling.inner_text
156
157
  case dt.inner_text
@@ -165,42 +166,44 @@ module Alexandria
165
166
  end
166
167
  end
167
168
 
168
- meta = doc / 'meta'
169
+ meta = doc / "meta"
169
170
  meta.each do |it|
170
171
  attrs = it.attributes
171
- property = attrs['property']
172
+ property = attrs["property"]
172
173
  next unless property
174
+
173
175
  case property
174
- when 'og:title'
175
- book_data[:title] = attrs['content']
176
- when 'og:image'
177
- book_data[:image_url] = attrs['content']
176
+ when "og:title"
177
+ book_data[:title] = attrs["content"]
178
+ when "og:image"
179
+ book_data[:image_url] = attrs["content"]
178
180
  end
179
181
  end
180
182
 
181
- author_links = doc / 'span.contributors a'
183
+ author_links = doc / "span.contributors a"
182
184
  authors = author_links.map(&:inner_text)
183
185
  book_data[:authors] = authors
184
186
 
185
- book_data[:binding] = ''
186
- selected_format = (doc / '#availableFormats li.selected a.tabTitle').first
187
+ book_data[:binding] = ""
188
+ selected_format = (doc / "#availableFormats li.selected a.tabTitle").first
187
189
  book_data[:binding] = selected_format.inner_text if selected_format
188
190
 
189
191
  book = Book.new(book_data[:title], book_data[:authors],
190
192
  book_data[:isbn], book_data[:publisher],
191
193
  book_data[:publication_year],
192
194
  book_data[:binding])
193
- return [book, book_data[:image_url]]
194
- rescue => ex
195
+ [book, book_data[:image_url]]
196
+ rescue StandardError => ex
195
197
  raise ex if ex.instance_of? NoResultsError
198
+
196
199
  trace = ex.backtrace.join("\n> ")
197
- log.warn {
198
- 'Failed parsing search results for BarnesAndNoble ' \
200
+ log.warn do
201
+ "Failed parsing search results for BarnesAndNoble " \
199
202
  "#{ex.message} #{trace}"
200
- }
203
+ end
201
204
  raise NoResultsError
202
205
  end
203
206
  end
204
- end # class BarnesAndNobleProvider
205
- end # class BookProviders
206
- end # module Alexandria
207
+ end
208
+ end
209
+ end
@@ -1,44 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby -*-
3
+ # This file is part of Alexandria.
4
4
  #
5
- # Copyright (C) 2009 Cathal Mc Ginley
6
- # Copyright (C) 2010 Sun Ning
7
- #
8
- # Alexandria is free software; you can redistribute it and/or
9
- # modify it under the terms of the GNU General Public License as
10
- # published by the Free Software Foundation; either version 2 of the
11
- # License, or (at your option) any later version.
12
- #
13
- # Alexandria is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- # General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public
19
- # License along with Alexandria; see the file COPYING. If not,
20
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
21
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
22
6
 
23
7
  # http://book.douban.com/
24
8
  # Douban.com book repository, provides many Chinese books.
25
9
 
26
10
  # Author: Sun Ning <classicning@gmail.com>, http://sunng.info/
27
11
 
28
- require 'cgi'
29
- require 'alexandria/net'
30
- require 'yaml'
12
+ require "cgi"
13
+ require "alexandria/net"
14
+ require "yaml"
31
15
 
32
16
  module Alexandria
33
17
  class BookProviders
34
18
  class DoubanProvider < GenericProvider
35
- include Alexandria::Logging
19
+ include Logging
36
20
 
37
- SITE = 'http://www.douban.com'
38
- BASE_URL = 'http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json'
21
+ SITE = "http://www.douban.com"
22
+ BASE_URL = "http://api.douban.com/book/subjects?q=%s&max-results=5&alt=json"
39
23
 
40
24
  def initialize
41
- super('Douban', 'Douban (China)')
25
+ super("Douban", "Douban (China)")
42
26
  prefs.read
43
27
  end
44
28
 
@@ -56,9 +40,9 @@ module Alexandria
56
40
  raise NoResultsError if results.empty?
57
41
 
58
42
  if type == SEARCH_BY_ISBN
59
- return results.first
43
+ results.first
60
44
  else
61
- return results
45
+ results
62
46
  end
63
47
  end
64
48
 
@@ -74,10 +58,10 @@ module Alexandria
74
58
  def json2yaml(json)
75
59
  # insert spaces after : and , except within strings
76
60
  # i.e. when followed by numeral, quote, { or [
77
- yaml = json.gsub(/(\:|\,)([0-9'"{\[])/) do |_match|
61
+ yaml = json.gsub(/(:|,)([0-9'"{\[])/) do |_match|
78
62
  "#{Regexp.last_match[1]} #{Regexp.last_match[2]}"
79
63
  end
80
- yaml.gsub!(/\\\//, '/') # unescape forward slashes
64
+ yaml.gsub!(%r{\\/}, "/") # unescape forward slashes
81
65
  yaml
82
66
  end
83
67
 
@@ -89,33 +73,33 @@ module Alexandria
89
73
  # dbresult = JSON.parse(response)
90
74
  dbresult = YAML.safe_load(json2yaml(response))
91
75
  # File.open(",douban.yaml", "wb") {|f| f.write(json2yaml(response)) }
92
- if dbresult['opensearch:totalResults']['$t'].to_i > 0
93
- for item in dbresult['entry']
94
- name = item['title']['$t']
76
+ if dbresult["opensearch:totalResults"]["$t"].to_i > 0
77
+ dbresult["entry"].each do |item|
78
+ name = item["title"]["$t"]
95
79
  isbn = nil
96
80
  publisher = nil
97
81
  pubdate = nil
98
82
  binding = nil
99
- for av in item['db:attribute']
100
- isbn = av['$t'] if av['@name'] == 'isbn13'
101
- publisher = av['$t'] if av['@name'] == 'publisher'
102
- pubdate = av['$t'] if av['@name'] == 'pubdate'
103
- binding = av['$t'] if av['@name'] == 'binding'
83
+ item["db:attribute"].each do |av|
84
+ isbn = av["$t"] if av["@name"] == "isbn13"
85
+ publisher = av["$t"] if av["@name"] == "publisher"
86
+ pubdate = av["$t"] if av["@name"] == "pubdate"
87
+ binding = av["$t"] if av["@name"] == "binding"
104
88
  end
105
- authors = if item['author']
106
- item['author'].map { |a| a['name']['$t'] }
89
+ authors = if item["author"]
90
+ item["author"].map { |a| a["name"]["$t"] }
107
91
  else
108
92
  []
109
93
  end
110
94
  image_url = nil
111
- for av in item['link']
112
- image_url = av['@href'] if av['@rel'] == 'image'
95
+ item["link"].each do |av|
96
+ image_url = av["@href"] if av["@rel"] == "image"
113
97
  end
114
98
  book = Book.new(name, authors, isbn, publisher, pubdate, binding)
115
99
  book_search_results << [book, image_url]
116
100
  end
117
101
  end
118
- rescue => ex
102
+ rescue StandardError => ex
119
103
  log.warn(ex.backtrace.join('\n'))
120
104
  end
121
105
  book_search_results
@@ -1,34 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2009 Cathal Mc Ginley
4
- # Copyright (C) 2014-2016 Matijs van Zuijlen
3
+ # This file is part of Alexandria.
5
4
  #
6
- # Alexandria is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU General Public License as
8
- # published by the Free Software Foundation; either version 2 of the
9
- # License, or (at your option) any later version.
10
- #
11
- # Alexandria is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public
17
- # License along with Alexandria; see the file COPYING. If not,
18
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
19
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
20
6
 
21
7
  # New Proxis provider, taken from Palatina MetaDataSource and modified
22
8
  # for Alexandria. (20 Dec 2009)
23
9
 
24
- require 'cgi'
25
- require 'alexandria/book_providers/web'
10
+ require "cgi"
11
+ require "alexandria/book_providers/web"
26
12
 
27
13
  module Alexandria
28
14
  class BookProviders
29
15
  class ProxisProvider < WebsiteBasedProvider
30
16
  # include GetText
31
- include Alexandria::Logging
17
+ include Logging
32
18
  # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
33
19
 
34
20
  # Proxis essentially has three book databases, NL, FR and EN.
@@ -36,14 +22,14 @@ module Alexandria
36
22
  # it adds most to Alexandria (Amazon already has French and
37
23
  # English titles).
38
24
 
39
- SITE = 'http://www.proxis.nl'
25
+ SITE = "http://www.proxis.nl"
40
26
  BASE_SEARCH_URL = "#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
41
- '&shop=100001NL&SelRubricLevel1Id=100001NL'
27
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
42
28
  ISBN_REDIRECT_BASE_URL = "#{SITE}/NLNL/Search/Index.aspx?search=%s" \
43
- '&shop=100001NL&SelRubricLevel1Id=100001NL'
29
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
44
30
 
45
31
  def initialize
46
- super('Proxis', 'Proxis (Belgium)')
32
+ super("Proxis", "Proxis (Belgium)")
47
33
  # prefs.add("lang", _("Language"), "fr",
48
34
  # LANGUAGES.keys)
49
35
  prefs.read
@@ -51,11 +37,12 @@ module Alexandria
51
37
 
52
38
  def search(criterion, type)
53
39
  req = create_search_uri(type, criterion)
54
- puts req if $DEBUG
40
+ log.debug { req }
55
41
  html_data = transport.get_response(URI.parse(req))
56
42
 
57
43
  results = parse_search_result_data(html_data.body)
58
44
  raise NoResultsError if results.empty?
45
+
59
46
  if type == SEARCH_BY_ISBN
60
47
  get_book_from_search_result(results.first)
61
48
  else
@@ -78,39 +65,40 @@ module Alexandria
78
65
  end
79
66
 
80
67
  def url(book)
81
- ISBN_REDIRECT_BASE_URL % Library.canonicalise_ean(book.isbn) if book.isbn.nil? || book.isbn.empty?
68
+ if book.isbn.nil? || book.isbn.empty?
69
+ ISBN_REDIRECT_BASE_URL % Library.canonicalise_ean(book.isbn)
70
+ end
82
71
  end
83
72
 
84
73
  ## from Palatina
85
74
  def text_of(node)
86
75
  if node.nil?
87
76
  nil
88
- else
89
- if node.text?
90
- node.to_html
91
- elsif node.elem?
92
- if node.children.nil?
93
- nil
94
- else
95
- node_text = node.children.map { |n| text_of(n) }.join
96
- node_text.strip.squeeze(' ')
97
- end
77
+ elsif node.text?
78
+ node.to_html
79
+ elsif node.elem?
80
+ if node.children.nil?
81
+ nil
82
+ else
83
+ node_text = node.children.map { |n| text_of(n) }.join
84
+ node_text.strip.squeeze(" ")
98
85
  end
99
- # node.inner_html.strip
100
86
  end
101
87
  end
102
88
 
103
89
  def parse_search_result_data(html)
104
90
  doc = html_to_doc(html)
105
91
  book_search_results = []
106
- items = doc.search('table.searchResult tr')
92
+ items = doc.search("table.searchResult tr")
107
93
  items.each do |item|
108
94
  result = {}
109
- title_link = item % 'h5 a'
95
+ title_link = item % "h5 a"
110
96
  if title_link
111
97
  result[:title] = text_of(title_link)
112
- result[:lookup_url] = title_link['href']
113
- result[:lookup_url] = "#{SITE}#{result[:lookup_url]}" unless result[:lookup_url] =~ /^http/
98
+ result[:lookup_url] = title_link["href"]
99
+ unless result[:lookup_url].start_with?("http")
100
+ result[:lookup_url] = "#{SITE}#{result[:lookup_url]}"
101
+ end
114
102
  end
115
103
  book_search_results << result
116
104
  end
@@ -120,9 +108,9 @@ module Alexandria
120
108
  book_search_results
121
109
  end
122
110
 
123
- def data_for_header(th)
124
- tr = th.parent
125
- td = tr.at('td')
111
+ def data_for_header(header)
112
+ tr = header.parent
113
+ td = tr.at("td")
126
114
  text_of(td) if td
127
115
  end
128
116
 
@@ -131,19 +119,19 @@ module Alexandria
131
119
  book_data = {}
132
120
  book_data[:authors] = []
133
121
  # TITLE
134
- if (title_header = doc.search('div.detailBlock h3'))
135
- header_spans = title_header.first.search('span')
122
+ if (title_header = doc.search("div.detailBlock h3"))
123
+ header_spans = title_header.first.search("span")
136
124
  title = text_of(header_spans.first)
137
125
  title = Regexp.last_match[1].strip if title =~ /(.+)-$/
138
126
  book_data[:title] = title
139
127
  end
140
128
 
141
- info_headers = doc.search('table.productInfoTable th')
129
+ info_headers = doc.search("table.productInfoTable th")
142
130
 
143
131
  isbns = []
144
132
  unless info_headers.empty?
145
133
  info_headers.each do |th|
146
- isbns << data_for_header(th) if th.inner_text =~ /(ISBN|EAN)/
134
+ isbns << data_for_header(th) if /(ISBN|EAN)/.match?(th.inner_text)
147
135
  end
148
136
  book_data[:isbn] = Library.canonicalise_ean(isbns.first)
149
137
  end
@@ -153,15 +141,16 @@ module Alexandria
153
141
  unless info_headers.empty?
154
142
  info_headers.each do |th|
155
143
  header_text = th.inner_text
156
- if header_text =~ /Type/
144
+ case header_text
145
+ when /Type/
157
146
  book_data[:binding] = data_for_header(th)
158
- elsif header_text =~ /Verschijningsdatum/
147
+ when /Verschijningsdatum/
159
148
  date = data_for_header(th)
160
- date =~ /\/([\d]{4})/
149
+ date =~ %r{/(\d{4})}
161
150
  book_data[:publish_year] = Regexp.last_match[1].to_i
162
- elsif header_text =~ /Auteur/
151
+ when /Auteur/
163
152
  book_data[:authors] << data_for_header(th)
164
- elsif header_text =~ /Uitgever/
153
+ when /Uitgever/
165
154
  book_data[:publisher] = data_for_header(th)
166
155
  end
167
156
  end
@@ -169,12 +158,12 @@ module Alexandria
169
158
 
170
159
  image_url = nil
171
160
  if (cover_img = doc.at("img[@id$='imgProduct']"))
172
- image_url = if cover_img['src'] =~ /^http/
173
- cover_img['src']
161
+ image_url = if cover_img["src"].start_with?("http")
162
+ cover_img["src"]
174
163
  else
175
164
  "#{SITE}/#{cover_img['src']}" # TODO: use html <base>
176
165
  end
177
- image_url = nil if image_url =~ /ProductNoCover/
166
+ image_url = nil if /ProductNoCover/.match?(image_url)
178
167
  end
179
168
 
180
169
  book = Book.new(book_data[:title], book_data[:authors],