alexandria-book-collection-manager 0.7.3 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) 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 +4 -1
  5. data/.rubocop.yml +86 -36
  6. data/.rubocop_todo.yml +58 -161
  7. data/.simplecov +5 -2
  8. data/CHANGELOG.md +56 -2
  9. data/Gemfile +4 -3
  10. data/INSTALL.md +23 -11
  11. data/README.md +52 -41
  12. data/Rakefile +78 -75
  13. data/alexandria-book-collection-manager.gemspec +50 -44
  14. data/bin/alexandria +12 -22
  15. data/doc/FAQ +1 -2
  16. data/doc/dependency_decisions.yml +27 -8
  17. data/lib/alexandria.rb +25 -23
  18. data/lib/alexandria/about.rb +50 -50
  19. data/lib/alexandria/book_providers.rb +86 -91
  20. data/lib/alexandria/book_providers/adlibris.rb +37 -74
  21. data/lib/alexandria/book_providers/amazon_aws.rb +94 -100
  22. data/lib/alexandria/book_providers/amazon_ecs_util.rb +289 -324
  23. data/lib/alexandria/book_providers/barnes_and_noble.rb +42 -42
  24. data/lib/alexandria/book_providers/douban.rb +25 -41
  25. data/lib/alexandria/book_providers/proxis.rb +34 -29
  26. data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
  27. data/lib/alexandria/book_providers/siciliano.rb +60 -64
  28. data/lib/alexandria/book_providers/thalia_provider.rb +161 -0
  29. data/lib/alexandria/book_providers/web.rb +5 -5
  30. data/lib/alexandria/book_providers/worldcat.rb +66 -95
  31. data/lib/alexandria/book_providers/z3950.rb +153 -169
  32. data/lib/alexandria/config.rb +1 -1
  33. data/lib/alexandria/console.rb +3 -3
  34. data/lib/alexandria/default_preferences.rb +37 -0
  35. data/lib/alexandria/execution_queue.rb +13 -12
  36. data/lib/alexandria/export_format.rb +8 -8
  37. data/lib/alexandria/export_library.rb +128 -127
  38. data/lib/alexandria/import_library.rb +102 -126
  39. data/lib/alexandria/import_library_csv.rb +41 -41
  40. data/lib/alexandria/library_collection.rb +6 -5
  41. data/lib/alexandria/library_sort_order.rb +4 -2
  42. data/lib/alexandria/library_store.rb +39 -28
  43. data/lib/alexandria/logging.rb +10 -14
  44. data/lib/alexandria/models/book.rb +5 -4
  45. data/lib/alexandria/models/library.rb +63 -53
  46. data/lib/alexandria/net.rb +5 -6
  47. data/lib/alexandria/preferences.rb +66 -63
  48. data/lib/alexandria/scanners.rb +2 -2
  49. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +17 -17
  50. data/lib/alexandria/scanners/keyboard.rb +8 -8
  51. data/lib/alexandria/smart_library.rb +110 -112
  52. data/lib/alexandria/ui.rb +15 -15
  53. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +2 -2
  54. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +108 -109
  55. data/lib/alexandria/ui/alert_dialog.rb +66 -0
  56. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +13 -9
  57. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
  58. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -38
  59. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +64 -157
  60. data/lib/alexandria/ui/builder_base.rb +1 -1
  61. data/lib/alexandria/ui/calendar_popup.rb +58 -0
  62. data/lib/alexandria/ui/callbacks.rb +187 -155
  63. data/lib/alexandria/ui/completion_models.rb +8 -22
  64. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  65. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  66. data/lib/alexandria/ui/dndable.rb +7 -7
  67. data/lib/alexandria/ui/error_dialog.rb +25 -0
  68. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +37 -58
  69. data/lib/alexandria/ui/icons.rb +38 -43
  70. data/lib/alexandria/ui/iconview.rb +12 -10
  71. data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
  72. data/lib/alexandria/ui/import_dialog.rb +157 -0
  73. data/lib/alexandria/ui/init.rb +30 -41
  74. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +9 -6
  75. data/lib/alexandria/ui/libraries_combo.rb +15 -14
  76. data/lib/alexandria/ui/listview.rb +69 -67
  77. data/lib/alexandria/ui/main_app.rb +24 -26
  78. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  79. data/lib/alexandria/ui/multi_drag_treeview.rb +8 -9
  80. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +113 -114
  81. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +22 -19
  82. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  83. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  84. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  85. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  86. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  87. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +7 -28
  88. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +53 -48
  89. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  90. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  91. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
  92. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  93. data/lib/alexandria/ui/sound.rb +11 -13
  94. data/lib/alexandria/ui/ui_manager.rb +216 -200
  95. data/lib/alexandria/version.rb +4 -19
  96. data/lib/alexandria/web_themes.rb +21 -21
  97. data/po/Makefile +2 -2
  98. data/po/cs.po +992 -875
  99. data/po/cy.po +961 -874
  100. data/po/de.po +990 -865
  101. data/po/el.po +989 -865
  102. data/po/es.po +985 -861
  103. data/po/fr.po +987 -867
  104. data/po/ga.po +908 -820
  105. data/po/gl.po +980 -860
  106. data/po/it.po +986 -864
  107. data/po/ja.po +969 -849
  108. data/po/mk.po +984 -860
  109. data/po/nb.po +979 -859
  110. data/po/nl.po +983 -860
  111. data/po/pl.po +1018 -971
  112. data/po/pt.po +988 -857
  113. data/po/pt_BR.po +983 -863
  114. data/po/ru.po +994 -871
  115. data/po/sk.po +989 -867
  116. data/po/sv.po +976 -856
  117. data/po/uk.po +972 -858
  118. data/po/zh_TW.po +974 -854
  119. data/schemas/alexandria.schemas +24 -2
  120. data/share/alexandria/glade/acquire_dialog__builder.glade +1 -1
  121. data/share/alexandria/glade/book_properties_dialog__builder.glade +1 -1
  122. data/share/alexandria/glade/main_app__builder.glade +6 -21
  123. data/share/alexandria/glade/new_book_dialog__builder.glade +1 -1
  124. data/share/alexandria/glade/preferences_dialog__builder.glade +1 -1
  125. data/share/gnome/help/alexandria/C/introduction.xml +0 -4
  126. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  127. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  128. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  129. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  130. data/share/gnome/help/alexandria/ja/introduction.xml +0 -4
  131. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  132. data/spec/alexandria/book_providers/thalia_provider_spec.rb +119 -0
  133. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  134. data/spec/alexandria/book_providers_spec.rb +62 -156
  135. data/spec/alexandria/book_spec.rb +12 -10
  136. data/spec/alexandria/console_spec.rb +6 -11
  137. data/spec/alexandria/export_library_spec.rb +47 -58
  138. data/spec/alexandria/library_spec.rb +121 -109
  139. data/spec/alexandria/library_store_spec.rb +8 -8
  140. data/spec/alexandria/preferences_spec.rb +44 -17
  141. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  142. data/spec/alexandria/smart_library_spec.rb +15 -15
  143. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  144. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  145. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  146. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  147. data/spec/alexandria/ui/book_properties_dialog_spec.rb +59 -0
  148. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  149. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  150. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  151. data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
  152. data/spec/alexandria/ui/icons_spec.rb +26 -0
  153. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  154. data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
  155. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  156. data/spec/alexandria/ui/main_app_spec.rb +7 -34
  157. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +51 -0
  158. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  159. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  160. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  161. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  162. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  163. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  164. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  165. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  166. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
  167. data/spec/alexandria/ui/sound_spec.rb +2 -2
  168. data/spec/alexandria/ui/ui_manager_spec.rb +44 -20
  169. data/spec/end_to_end/basic_run_spec.rb +21 -38
  170. data/spec/fixtures/cover.jpg +0 -0
  171. data/spec/spec_helper.rb +54 -10
  172. data/tasks/setup.rb +2 -2
  173. data/tasks/spec.rake +11 -11
  174. data/util/rake/fileinstall.rb +38 -35
  175. data/util/rake/gettextgenerate.rb +7 -7
  176. data/util/rake/omfgenerate.rb +7 -7
  177. metadata +158 -45
  178. data/dogtail/basic_run_test.py +0 -9
  179. data/lib/alexandria/book_providers/renaud.rb +0 -155
  180. data/lib/alexandria/book_providers/thalia.rb +0 -198
  181. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -63
  182. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -176
  183. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -62
  184. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -563
  185. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -61
  186. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -423
  187. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  188. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  189. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
  190. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  191. data/spec/alexandria/utilities_spec.rb +0 -52
  192. 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,7 @@ 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
61
  if limit < 10
62
62
  sleep 0.1
@@ -67,9 +67,9 @@ module Alexandria
67
67
  response = agent.get(uri_str)
68
68
  log.debug { response.inspect }
69
69
  case response
70
- when Net::HTTPSuccess then response
71
- when Net::HTTPRedirection then
72
- redirect = URI.parse response['Location']
70
+ when Net::HTTPSuccess then response
71
+ when Net::HTTPRedirection
72
+ redirect = URI.parse response["Location"]
73
73
  redirect = URI.parse(uri_str) + redirect if redirect.relative?
74
74
  fetch_redirectly(redirect.to_s, (limit - 1))
75
75
  else
@@ -79,7 +79,7 @@ module Alexandria
79
79
 
80
80
  def search(criterion, type)
81
81
  req = create_search_uri(type, criterion)
82
- puts "Requesting #{req}" if $DEBUG
82
+ log.debug { "Requesting #{req}" }
83
83
  html_data = fetch_redirectly(req)
84
84
 
85
85
  if type == SEARCH_BY_ISBN
@@ -101,10 +101,10 @@ module Alexandria
101
101
 
102
102
  def create_search_uri(search_type, search_term)
103
103
  (search_type_code = {
104
- SEARCH_BY_AUTHORS => 'ATH',
105
- SEARCH_BY_TITLE => 'TTL',
106
- SEARCH_BY_KEYWORD => 'WRD' # SEARCH_BY_PUBLISHER => 'PBL' # not implemented
107
- }[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]) || ""
108
108
  if search_type == SEARCH_BY_ISBN
109
109
  BASE_ISBN_SEARCH_URL % Library.canonicalise_ean(search_term) # isbn-13
110
110
  else
@@ -128,19 +128,19 @@ module Alexandria
128
128
  result = {}
129
129
  # img = div % 'div.book-image/a/img'
130
130
  # result[:image_url] = img['src'] if img
131
- title_header = div % 'h2'
132
- title_links = title_header / 'a'
131
+ title_header = div % "h2"
132
+ title_links = title_header / "a"
133
133
  result[:title] = title_links.first.inner_text
134
- result[:url] = title_links.first['href']
134
+ result[:url] = title_links.first["href"]
135
135
 
136
136
  book_search_results << result
137
137
  end
138
138
  rescue StandardError => ex
139
139
  trace = ex.backtrace.join("\n> ")
140
- log.warn {
141
- 'Failed parsing search results for Barnes & Noble ' \
140
+ log.warn do
141
+ "Failed parsing search results for Barnes & Noble " \
142
142
  "#{ex.message} #{trace}"
143
- }
143
+ end
144
144
  end
145
145
  book_search_results
146
146
  end
@@ -150,8 +150,8 @@ module Alexandria
150
150
  begin
151
151
  book_data = {}
152
152
 
153
- dl = (doc / 'dl').first
154
- dts = dl.children_of_type('dt')
153
+ dl = (doc / "dl").first
154
+ dts = dl.children_of_type("dt")
155
155
  dts.each do |dt|
156
156
  value = dt.next_sibling.inner_text
157
157
  case dt.inner_text
@@ -166,44 +166,44 @@ module Alexandria
166
166
  end
167
167
  end
168
168
 
169
- meta = doc / 'meta'
169
+ meta = doc / "meta"
170
170
  meta.each do |it|
171
171
  attrs = it.attributes
172
- property = attrs['property']
172
+ property = attrs["property"]
173
173
  next unless property
174
174
 
175
175
  case property
176
- when 'og:title'
177
- book_data[:title] = attrs['content']
178
- when 'og:image'
179
- 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"]
180
180
  end
181
181
  end
182
182
 
183
- author_links = doc / 'span.contributors a'
183
+ author_links = doc / "span.contributors a"
184
184
  authors = author_links.map(&:inner_text)
185
185
  book_data[:authors] = authors
186
186
 
187
- book_data[:binding] = ''
188
- selected_format = (doc / '#availableFormats li.selected a.tabTitle').first
187
+ book_data[:binding] = ""
188
+ selected_format = (doc / "#availableFormats li.selected a.tabTitle").first
189
189
  book_data[:binding] = selected_format.inner_text if selected_format
190
190
 
191
191
  book = Book.new(book_data[:title], book_data[:authors],
192
192
  book_data[:isbn], book_data[:publisher],
193
193
  book_data[:publication_year],
194
194
  book_data[:binding])
195
- return [book, book_data[:image_url]]
195
+ [book, book_data[:image_url]]
196
196
  rescue StandardError => ex
197
197
  raise ex if ex.instance_of? NoResultsError
198
198
 
199
199
  trace = ex.backtrace.join("\n> ")
200
- log.warn {
201
- 'Failed parsing search results for BarnesAndNoble ' \
200
+ log.warn do
201
+ "Failed parsing search results for BarnesAndNoble " \
202
202
  "#{ex.message} #{trace}"
203
- }
203
+ end
204
204
  raise NoResultsError
205
205
  end
206
206
  end
207
- end # class BarnesAndNobleProvider
208
- end # class BookProviders
209
- 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,27 +73,27 @@ 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]
@@ -7,14 +7,14 @@
7
7
  # New Proxis provider, taken from Palatina MetaDataSource and modified
8
8
  # for Alexandria. (20 Dec 2009)
9
9
 
10
- require 'cgi'
11
- require 'alexandria/book_providers/web'
10
+ require "cgi"
11
+ require "alexandria/book_providers/web"
12
12
 
13
13
  module Alexandria
14
14
  class BookProviders
15
15
  class ProxisProvider < WebsiteBasedProvider
16
16
  # include GetText
17
- include Alexandria::Logging
17
+ include Logging
18
18
  # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
19
19
 
20
20
  # Proxis essentially has three book databases, NL, FR and EN.
@@ -22,14 +22,14 @@ module Alexandria
22
22
  # it adds most to Alexandria (Amazon already has French and
23
23
  # English titles).
24
24
 
25
- SITE = 'http://www.proxis.nl'
25
+ SITE = "http://www.proxis.nl"
26
26
  BASE_SEARCH_URL = "#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
27
- '&shop=100001NL&SelRubricLevel1Id=100001NL'
27
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
28
28
  ISBN_REDIRECT_BASE_URL = "#{SITE}/NLNL/Search/Index.aspx?search=%s" \
29
- '&shop=100001NL&SelRubricLevel1Id=100001NL'
29
+ "&shop=100001NL&SelRubricLevel1Id=100001NL"
30
30
 
31
31
  def initialize
32
- super('Proxis', 'Proxis (Belgium)')
32
+ super("Proxis", "Proxis (Belgium)")
33
33
  # prefs.add("lang", _("Language"), "fr",
34
34
  # LANGUAGES.keys)
35
35
  prefs.read
@@ -37,7 +37,7 @@ module Alexandria
37
37
 
38
38
  def search(criterion, type)
39
39
  req = create_search_uri(type, criterion)
40
- puts req if $DEBUG
40
+ log.debug { req }
41
41
  html_data = transport.get_response(URI.parse(req))
42
42
 
43
43
  results = parse_search_result_data(html_data.body)
@@ -65,7 +65,9 @@ module Alexandria
65
65
  end
66
66
 
67
67
  def url(book)
68
- 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
69
71
  end
70
72
 
71
73
  ## from Palatina
@@ -79,7 +81,7 @@ module Alexandria
79
81
  nil
80
82
  else
81
83
  node_text = node.children.map { |n| text_of(n) }.join
82
- node_text.strip.squeeze(' ')
84
+ node_text.strip.squeeze(" ")
83
85
  end
84
86
  end
85
87
  end
@@ -87,14 +89,16 @@ module Alexandria
87
89
  def parse_search_result_data(html)
88
90
  doc = html_to_doc(html)
89
91
  book_search_results = []
90
- items = doc.search('table.searchResult tr')
92
+ items = doc.search("table.searchResult tr")
91
93
  items.each do |item|
92
94
  result = {}
93
- title_link = item % 'h5 a'
95
+ title_link = item % "h5 a"
94
96
  if title_link
95
97
  result[:title] = text_of(title_link)
96
- result[:lookup_url] = title_link['href']
97
- 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
98
102
  end
99
103
  book_search_results << result
100
104
  end
@@ -104,9 +108,9 @@ module Alexandria
104
108
  book_search_results
105
109
  end
106
110
 
107
- def data_for_header(th)
108
- tr = th.parent
109
- td = tr.at('td')
111
+ def data_for_header(header)
112
+ tr = header.parent
113
+ td = tr.at("td")
110
114
  text_of(td) if td
111
115
  end
112
116
 
@@ -115,19 +119,19 @@ module Alexandria
115
119
  book_data = {}
116
120
  book_data[:authors] = []
117
121
  # TITLE
118
- if (title_header = doc.search('div.detailBlock h3'))
119
- header_spans = title_header.first.search('span')
122
+ if (title_header = doc.search("div.detailBlock h3"))
123
+ header_spans = title_header.first.search("span")
120
124
  title = text_of(header_spans.first)
121
125
  title = Regexp.last_match[1].strip if title =~ /(.+)-$/
122
126
  book_data[:title] = title
123
127
  end
124
128
 
125
- info_headers = doc.search('table.productInfoTable th')
129
+ info_headers = doc.search("table.productInfoTable th")
126
130
 
127
131
  isbns = []
128
132
  unless info_headers.empty?
129
133
  info_headers.each do |th|
130
- isbns << data_for_header(th) if th.inner_text =~ /(ISBN|EAN)/
134
+ isbns << data_for_header(th) if /(ISBN|EAN)/.match?(th.inner_text)
131
135
  end
132
136
  book_data[:isbn] = Library.canonicalise_ean(isbns.first)
133
137
  end
@@ -137,15 +141,16 @@ module Alexandria
137
141
  unless info_headers.empty?
138
142
  info_headers.each do |th|
139
143
  header_text = th.inner_text
140
- if header_text =~ /Type/
144
+ case header_text
145
+ when /Type/
141
146
  book_data[:binding] = data_for_header(th)
142
- elsif header_text =~ /Verschijningsdatum/
147
+ when /Verschijningsdatum/
143
148
  date = data_for_header(th)
144
- date =~ /\/([\d]{4})/
149
+ date =~ %r{/(\d{4})}
145
150
  book_data[:publish_year] = Regexp.last_match[1].to_i
146
- elsif header_text =~ /Auteur/
151
+ when /Auteur/
147
152
  book_data[:authors] << data_for_header(th)
148
- elsif header_text =~ /Uitgever/
153
+ when /Uitgever/
149
154
  book_data[:publisher] = data_for_header(th)
150
155
  end
151
156
  end
@@ -153,12 +158,12 @@ module Alexandria
153
158
 
154
159
  image_url = nil
155
160
  if (cover_img = doc.at("img[@id$='imgProduct']"))
156
- image_url = if cover_img['src'] =~ /^http/
157
- cover_img['src']
161
+ image_url = if cover_img["src"].start_with?("http")
162
+ cover_img["src"]
158
163
  else
159
164
  "#{SITE}/#{cover_img['src']}" # TODO: use html <base>
160
165
  end
161
- image_url = nil if image_url =~ /ProductNoCover/
166
+ image_url = nil if /ProductNoCover/.match?(image_url)
162
167
  end
163
168
 
164
169
  book = Book.new(book_data[:title], book_data[:authors],
@@ -22,103 +22,104 @@ module Alexandria
22
22
  # A really simple regex-based parser to grab data out of marc text records.
23
23
  class PseudoMarcParser
24
24
  BNF_FR_MAPPINGS = {
25
- title: ['200', 'a'],
26
- authors: ['700', 'a'],
27
- isbn: ['010', 'a'],
28
- publisher: ['210', 'g'],
29
- year: ['210', 'd'],
30
- binding: ['225', 'a'],
31
- notes: ['520', 'a']
25
+ title: ["200", "a"],
26
+ authors: ["700", "a"],
27
+ isbn: ["010", "a"],
28
+ publisher: ["210", "g"],
29
+ year: ["210", "d"],
30
+ binding: ["225", "a"],
31
+ notes: ["520", "a"]
32
32
  }.freeze
33
33
 
34
34
  USMARC_MAPPINGS = {
35
- title: ['245', 'a', 'b'],
36
- authors: ['100', 'a'],
37
- isbn: ['020', 'a'],
38
- publisher: ['490', 'a'],
39
- year: ['260', 'c'],
40
- binding: ['020', 'a'], # listed with isbn here
41
- notes: ['520', 'a']
35
+ title: ["245", "a", "b"],
36
+ authors: ["100", "a"],
37
+ isbn: ["020", "a"],
38
+ publisher: ["490", "a"],
39
+ year: ["260", "c"],
40
+ binding: ["020", "a"], # listed with isbn here
41
+ notes: ["520", "a"]
42
42
  }.freeze
43
43
 
44
- def self.get_fields(data, type, stripping, m = USMARC_MAPPINGS)
45
- field = ''
46
- m[type][1..m[type].length - 1].each do |part|
44
+ def self.get_fields(data, type, stripping, mappings = USMARC_MAPPINGS)
45
+ field = ""
46
+ mappings[type][1..mappings[type].length - 1].each do |part|
47
47
  if data.first[part]
48
48
  part_data = data.first[part].strip
49
49
  if part_data =~ stripping
50
50
  part_data = Regexp.last_match[1]
51
51
  part_data = part_data.strip
52
52
  end
53
- field += ': ' if field != ''
53
+ field += ": " if field != ""
54
54
  field += part_data
55
55
  end
56
56
  end
57
- field = nil if field == ''
57
+ field = nil if field == ""
58
58
  field
59
59
  end
60
60
 
61
- def self.marc_text_to_book(marc, m = USMARC_MAPPINGS)
61
+ def self.marc_text_to_book(marc, mappings = USMARC_MAPPINGS)
62
62
  details = marc_text_to_details(marc)
63
- unless details.empty?
64
- title = nil
65
- title_data = details[m[:title][0]]
66
- if title_data
67
- title_data_all = get_fields(title_data, :title, /(.*)[\/:]$/, m)
68
- title = title_data_all if title_data_all
69
- end
63
+ return if details.empty?
70
64
 
71
- authors = []
72
- author_data = details[m[:authors][0]]
73
- author_data&.each do |ad|
74
- author = ad[m[:authors][1]]
75
- if author
76
- author = author.strip
77
- author = Regexp.last_match[1] if author =~ /(.*),$/
78
- authors << author
79
- end
80
- end
65
+ title = nil
66
+ title_data = details[mappings[:title][0]]
67
+ if title_data
68
+ title_data_all = get_fields(title_data, :title, %r{(.*)[/:]$}, mappings)
69
+ title = title_data_all if title_data_all
70
+ end
81
71
 
82
- isbn = nil
83
- binding = nil
84
- isbn_data = details[m[:isbn][0]]
85
- if isbn_data
86
- isbn = Regexp.last_match[1] if isbn_data.first[m[:isbn][1]] =~ /([-0-9xX]+)/
72
+ authors = []
73
+ author_data = details[mappings[:authors][0]]
74
+ author_data&.each do |ad|
75
+ author = ad[mappings[:authors][1]]
76
+ if author
77
+ author = author.strip
78
+ author = Regexp.last_match[1] if author =~ /(.*),$/
79
+ authors << author
87
80
  end
81
+ end
88
82
 
89
- binding_data = details[m[:binding][0]]
90
- if binding_data
91
- binding = Regexp.last_match[1] if binding_data.first[m[:binding][1]] =~ /([a-zA-Z][a-z\s]+[a-z])/
92
- end
83
+ isbn = nil
84
+ binding = nil
85
+ isbn_data = details[mappings[:isbn][0]]
86
+ if isbn_data && isbn_data.first[mappings[:isbn][1]] =~ /([-0-9xX]+)/
87
+ isbn = Regexp.last_match[1]
88
+ end
93
89
 
94
- publisher = nil
95
- publisher_data = details[m[:publisher][0]]
96
- publisher = publisher_data.first[m[:publisher][1]] if publisher_data
90
+ binding_data = details[mappings[:binding][0]]
91
+ if binding_data &&
92
+ binding_data.first[mappings[:binding][1]] =~ /([a-zA-Z][a-z\s]+[a-z])/
93
+ binding = Regexp.last_match[1]
94
+ end
97
95
 
98
- year = nil
99
- publication_data = details[m[:year][0]]
100
- if publication_data
101
- year = publication_data.first[m[:year][1]]
102
- year = Regexp.last_match[1].to_i if year =~ /(\d+)/
103
- end
96
+ publisher = nil
97
+ publisher_data = details[mappings[:publisher][0]]
98
+ publisher = publisher_data.first[mappings[:publisher][1]] if publisher_data
104
99
 
105
- notes = ''
106
- notes_data = details[m[:notes][0]]
107
- notes_data&.each do |note|
108
- txt = note[m[:notes][1]]
109
- notes += txt if txt
110
- end
100
+ year = nil
101
+ publication_data = details[mappings[:year][0]]
102
+ if publication_data
103
+ year = publication_data.first[mappings[:year][1]]
104
+ year = Regexp.last_match[1].to_i if year =~ /(\d+)/
105
+ end
111
106
 
112
- if title.nil? && isbn.nil?
113
- # probably didn't undertand the MARC dialect
114
- return nil
115
- end
107
+ notes = ""
108
+ notes_data = details[mappings[:notes][0]]
109
+ notes_data&.each do |note|
110
+ txt = note[mappings[:notes][1]]
111
+ notes += txt if txt
112
+ end
116
113
 
117
- book = Alexandria::Book.new(title, authors, isbn,
118
- publisher, year, binding)
119
- book.notes = notes unless notes.empty?
120
- book
114
+ if title.nil? && isbn.nil?
115
+ # probably didn't undertand the MARC dialect
116
+ return nil
121
117
  end
118
+
119
+ book = Alexandria::Book.new(title, authors, isbn,
120
+ publisher, year, binding)
121
+ book.notes = notes unless notes.empty?
122
+ book
122
123
  end
123
124
 
124
125
  def self.marc_text_to_details(marc)
@@ -130,31 +131,22 @@ module Alexandria
130
131
 
131
132
  this_line_data = {}
132
133
 
133
- # puts code
134
- # puts data
135
134
  d_idx = 0
136
135
  while d_idx < data.size
137
136
  d_str = data[d_idx..-1]
138
- # puts d_str
139
- if (idx = d_str =~ /\$([a-z]) ([^\$]+)/)
140
- # puts idx
141
- sub_code = Regexp.last_match[1]
142
- sub_data = Regexp.last_match[2]
143
- this_line_data[sub_code] = sub_data
144
- # puts " " + $1
145
- # puts " " + $2
146
- # puts idx
147
- d_idx += idx + 2 # (2 extra to push beyond this '$a' etc.)
148
- else
149
- break
150
- end
137
+ idx = d_str =~ /\$([a-z]) ([^$]+)/
138
+ break unless idx
139
+
140
+ sub_code = Regexp.last_match[1]
141
+ sub_data = Regexp.last_match[2]
142
+ this_line_data[sub_code] = sub_data
143
+ d_idx += idx + 2 # (2 extra to push beyond this '$a' etc.)
151
144
  end
152
145
 
153
146
  unless this_line_data.empty?
154
147
  details[code] = [] unless details.key?(code)
155
148
  details[code] << this_line_data
156
149
  end
157
-
158
150
  end
159
151
  end
160
152
  details