alexandria-book-collection-manager 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -25
  3. data/.rubocop_todo.yml +87 -67
  4. data/CHANGELOG.md +12 -1
  5. data/Gemfile +4 -3
  6. data/README.md +16 -6
  7. data/Rakefile +71 -72
  8. data/alexandria-book-collection-manager.gemspec +44 -44
  9. data/bin/alexandria +12 -12
  10. data/lib/alexandria.rb +22 -22
  11. data/lib/alexandria/about.rb +50 -50
  12. data/lib/alexandria/book_providers.rb +50 -50
  13. data/lib/alexandria/book_providers/adlibris.rb +28 -44
  14. data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
  15. data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
  16. data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
  17. data/lib/alexandria/book_providers/douban.rb +21 -37
  18. data/lib/alexandria/book_providers/proxis.rb +24 -24
  19. data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
  20. data/lib/alexandria/book_providers/renaud.rb +44 -57
  21. data/lib/alexandria/book_providers/siciliano.rb +39 -39
  22. data/lib/alexandria/book_providers/thalia.rb +33 -33
  23. data/lib/alexandria/book_providers/web.rb +5 -5
  24. data/lib/alexandria/book_providers/worldcat.rb +44 -69
  25. data/lib/alexandria/book_providers/z3950.rb +94 -109
  26. data/lib/alexandria/config.rb +1 -1
  27. data/lib/alexandria/console.rb +3 -3
  28. data/lib/alexandria/export_format.rb +8 -8
  29. data/lib/alexandria/export_library.rb +112 -113
  30. data/lib/alexandria/import_library.rb +45 -45
  31. data/lib/alexandria/import_library_csv.rb +30 -30
  32. data/lib/alexandria/library_collection.rb +4 -4
  33. data/lib/alexandria/library_sort_order.rb +1 -1
  34. data/lib/alexandria/library_store.rb +14 -14
  35. data/lib/alexandria/logging.rb +5 -5
  36. data/lib/alexandria/models/book.rb +1 -1
  37. data/lib/alexandria/models/library.rb +36 -36
  38. data/lib/alexandria/net.rb +5 -5
  39. data/lib/alexandria/preferences.rb +32 -32
  40. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
  41. data/lib/alexandria/scanners/keyboard.rb +5 -5
  42. data/lib/alexandria/smart_library.rb +53 -53
  43. data/lib/alexandria/ui.rb +15 -15
  44. data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
  45. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
  46. data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
  47. data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
  48. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
  49. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
  50. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
  51. data/lib/alexandria/ui/builder_base.rb +1 -1
  52. data/lib/alexandria/ui/callbacks.rb +95 -91
  53. data/lib/alexandria/ui/completion_models.rb +7 -21
  54. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  55. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  56. data/lib/alexandria/ui/dndable.rb +7 -7
  57. data/lib/alexandria/ui/error_dialog.rb +25 -0
  58. data/lib/alexandria/ui/{dialogs/export_dialog.rb → export_dialog.rb} +22 -42
  59. data/lib/alexandria/ui/icons.rb +6 -6
  60. data/lib/alexandria/ui/iconview.rb +7 -7
  61. data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
  62. data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
  63. data/lib/alexandria/ui/init.rb +16 -29
  64. data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
  65. data/lib/alexandria/ui/libraries_combo.rb +7 -7
  66. data/lib/alexandria/ui/listview.rb +40 -40
  67. data/lib/alexandria/ui/main_app.rb +22 -24
  68. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  69. data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
  70. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
  71. data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
  72. data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
  73. data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
  74. data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
  75. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
  76. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  77. data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
  78. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
  79. data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
  80. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
  81. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
  82. data/lib/alexandria/ui/sound.rb +8 -8
  83. data/lib/alexandria/ui/ui_manager.rb +136 -135
  84. data/lib/alexandria/version.rb +4 -19
  85. data/lib/alexandria/web_themes.rb +8 -8
  86. data/po/cs.po +97 -97
  87. data/po/cy.po +97 -97
  88. data/po/de.po +97 -97
  89. data/po/el.po +97 -97
  90. data/po/es.po +97 -97
  91. data/po/fr.po +97 -97
  92. data/po/ga.po +97 -97
  93. data/po/gl.po +97 -97
  94. data/po/it.po +97 -97
  95. data/po/ja.po +97 -97
  96. data/po/mk.po +97 -97
  97. data/po/nb.po +97 -97
  98. data/po/nl.po +97 -97
  99. data/po/pl.po +97 -97
  100. data/po/pt.po +97 -97
  101. data/po/pt_BR.po +97 -97
  102. data/po/ru.po +97 -97
  103. data/po/sk.po +97 -97
  104. data/po/sv.po +97 -97
  105. data/po/uk.po +97 -97
  106. data/po/zh_TW.po +97 -97
  107. data/schemas/alexandria.schemas +24 -2
  108. data/spec/alexandria/book_providers_spec.rb +65 -82
  109. data/spec/alexandria/book_spec.rb +12 -10
  110. data/spec/alexandria/console_spec.rb +9 -9
  111. data/spec/alexandria/export_library_spec.rb +31 -31
  112. data/spec/alexandria/library_spec.rb +86 -86
  113. data/spec/alexandria/library_store_spec.rb +8 -8
  114. data/spec/alexandria/preferences_spec.rb +18 -17
  115. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  116. data/spec/alexandria/smart_library_spec.rb +15 -15
  117. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  118. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  119. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  120. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  121. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  122. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  123. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  124. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  125. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  126. data/spec/alexandria/ui/iconview_spec.rb +7 -21
  127. data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
  128. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  129. data/spec/alexandria/ui/main_app_spec.rb +6 -6
  130. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  131. data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
  132. data/spec/alexandria/ui/new_provider_dialog_spec.rb +14 -0
  133. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
  134. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  135. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
  136. data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -0
  137. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  138. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  139. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +18 -0
  140. data/spec/alexandria/ui/sound_spec.rb +2 -2
  141. data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
  142. data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
  143. data/spec/alexandria/utilities_spec.rb +6 -6
  144. data/spec/end_to_end/basic_run_spec.rb +24 -36
  145. data/spec/spec_helper.rb +9 -9
  146. data/tasks/dogtail.rake +1 -1
  147. data/tasks/setup.rb +2 -2
  148. data/tasks/spec.rake +11 -11
  149. data/util/rake/fileinstall.rb +25 -25
  150. data/util/rake/gettextgenerate.rb +7 -7
  151. data/util/rake/omfgenerate.rb +7 -7
  152. metadata +59 -33
  153. data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
  154. data/spec/alexandria/ui/dialogs_spec.rb +0 -162
  155. data/spec/alexandria/ui/sidepane_spec.rb +0 -29
@@ -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
38
  include Alexandria::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
@@ -69,7 +69,7 @@ module Alexandria
69
69
  case response
70
70
  when Net::HTTPSuccess then response
71
71
  when Net::HTTPRedirection then
72
- redirect = URI.parse response['Location']
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
@@ -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,26 +166,26 @@ 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],
@@ -197,10 +197,10 @@ module Alexandria
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
@@ -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
19
  include Alexandria::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
 
@@ -77,7 +61,7 @@ module Alexandria
77
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,8 +7,8 @@
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
@@ -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
@@ -79,7 +79,7 @@ module Alexandria
79
79
  nil
80
80
  else
81
81
  node_text = node.children.map { |n| text_of(n) }.join
82
- node_text.strip.squeeze(' ')
82
+ node_text.strip.squeeze(" ")
83
83
  end
84
84
  end
85
85
  end
@@ -87,14 +87,14 @@ module Alexandria
87
87
  def parse_search_result_data(html)
88
88
  doc = html_to_doc(html)
89
89
  book_search_results = []
90
- items = doc.search('table.searchResult tr')
90
+ items = doc.search("table.searchResult tr")
91
91
  items.each do |item|
92
92
  result = {}
93
- title_link = item % 'h5 a'
93
+ title_link = item % "h5 a"
94
94
  if title_link
95
95
  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/
96
+ result[:lookup_url] = title_link["href"]
97
+ result[:lookup_url] = "#{SITE}#{result[:lookup_url]}" unless /^http/.match?(result[:lookup_url])
98
98
  end
99
99
  book_search_results << result
100
100
  end
@@ -106,7 +106,7 @@ module Alexandria
106
106
 
107
107
  def data_for_header(th)
108
108
  tr = th.parent
109
- td = tr.at('td')
109
+ td = tr.at("td")
110
110
  text_of(td) if td
111
111
  end
112
112
 
@@ -115,19 +115,19 @@ module Alexandria
115
115
  book_data = {}
116
116
  book_data[:authors] = []
117
117
  # TITLE
118
- if (title_header = doc.search('div.detailBlock h3'))
119
- header_spans = title_header.first.search('span')
118
+ if (title_header = doc.search("div.detailBlock h3"))
119
+ header_spans = title_header.first.search("span")
120
120
  title = text_of(header_spans.first)
121
121
  title = Regexp.last_match[1].strip if title =~ /(.+)-$/
122
122
  book_data[:title] = title
123
123
  end
124
124
 
125
- info_headers = doc.search('table.productInfoTable th')
125
+ info_headers = doc.search("table.productInfoTable th")
126
126
 
127
127
  isbns = []
128
128
  unless info_headers.empty?
129
129
  info_headers.each do |th|
130
- isbns << data_for_header(th) if th.inner_text =~ /(ISBN|EAN)/
130
+ isbns << data_for_header(th) if /(ISBN|EAN)/.match?(th.inner_text)
131
131
  end
132
132
  book_data[:isbn] = Library.canonicalise_ean(isbns.first)
133
133
  end
@@ -137,15 +137,15 @@ module Alexandria
137
137
  unless info_headers.empty?
138
138
  info_headers.each do |th|
139
139
  header_text = th.inner_text
140
- if header_text =~ /Type/
140
+ if /Type/.match?(header_text)
141
141
  book_data[:binding] = data_for_header(th)
142
- elsif header_text =~ /Verschijningsdatum/
142
+ elsif /Verschijningsdatum/.match?(header_text)
143
143
  date = data_for_header(th)
144
- date =~ /\/([\d]{4})/
144
+ date =~ %r{/([\d]{4})}
145
145
  book_data[:publish_year] = Regexp.last_match[1].to_i
146
- elsif header_text =~ /Auteur/
146
+ elsif /Auteur/.match?(header_text)
147
147
  book_data[:authors] << data_for_header(th)
148
- elsif header_text =~ /Uitgever/
148
+ elsif /Uitgever/.match?(header_text)
149
149
  book_data[:publisher] = data_for_header(th)
150
150
  end
151
151
  end
@@ -153,12 +153,12 @@ module Alexandria
153
153
 
154
154
  image_url = nil
155
155
  if (cover_img = doc.at("img[@id$='imgProduct']"))
156
- image_url = if cover_img['src'] =~ /^http/
157
- cover_img['src']
156
+ image_url = if /^http/.match?(cover_img["src"])
157
+ cover_img["src"]
158
158
  else
159
159
  "#{SITE}/#{cover_img['src']}" # TODO: use html <base>
160
160
  end
161
- image_url = nil if image_url =~ /ProductNoCover/
161
+ image_url = nil if /ProductNoCover/.match?(image_url)
162
162
  end
163
163
 
164
164
  book = Book.new(book_data[:title], book_data[:authors],
@@ -22,27 +22,27 @@ 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
44
  def self.get_fields(data, type, stripping, m = USMARC_MAPPINGS)
45
- field = ''
45
+ field = ""
46
46
  m[type][1..m[type].length - 1].each do |part|
47
47
  if data.first[part]
48
48
  part_data = data.first[part].strip
@@ -50,11 +50,11 @@ module Alexandria
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
 
@@ -64,7 +64,7 @@ module Alexandria
64
64
  title = nil
65
65
  title_data = details[m[:title][0]]
66
66
  if title_data
67
- title_data_all = get_fields(title_data, :title, /(.*)[\/:]$/, m)
67
+ title_data_all = get_fields(title_data, :title, %r{(.*)[/:]$}, m)
68
68
  title = title_data_all if title_data_all
69
69
  end
70
70
 
@@ -102,7 +102,7 @@ module Alexandria
102
102
  year = Regexp.last_match[1].to_i if year =~ /(\d+)/
103
103
  end
104
104
 
105
- notes = ''
105
+ notes = ""
106
106
  notes_data = details[m[:notes][0]]
107
107
  notes_data&.each do |note|
108
108
  txt = note[m[:notes][1]]
@@ -1,57 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2005-2006-2006 Mathieu Leduc-Hamel
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
  # http://en.wikipedia.org/wiki/Renaud-Bray
21
8
 
22
- require 'net/http'
23
- require 'cgi'
9
+ require "net/http"
10
+ require "cgi"
24
11
 
25
12
  module Alexandria
26
13
  class BookProviders
27
14
  class RENAUDProvider < GenericProvider
28
15
  include GetText
29
16
  # GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
30
- BASE_URI = 'http://www.renaud-bray.com/'
31
- ACCENTUATED_CHARS = 'áàâäçéèêëíìîïóòôöúùûü'
17
+ BASE_URI = "http://www.renaud-bray.com/"
18
+ ACCENTUATED_CHARS = "áàâäçéèêëíìîïóòôöúùûü"
32
19
 
33
20
  def initialize
34
- super('RENAUD', 'Renaud-Bray (Canada)')
21
+ super("RENAUD", "Renaud-Bray (Canada)")
35
22
  end
36
23
 
37
24
  def search(criterion, type)
38
- criterion = criterion.encode('ISO-8859-1')
25
+ criterion = criterion.encode("ISO-8859-1")
39
26
  req = BASE_URI +
40
- 'francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre' \
41
- '&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri='
27
+ "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre" \
28
+ "&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri="
42
29
  req += case type
43
30
  when SEARCH_BY_ISBN
44
- 'ISBN'
31
+ "ISBN"
45
32
  when SEARCH_BY_TITLE
46
- 'Titre'
33
+ "Titre"
47
34
  when SEARCH_BY_AUTHORS
48
- 'Auteur'
35
+ "Auteur"
49
36
  when SEARCH_BY_KEYWORD
50
- ''
37
+ ""
51
38
  else
52
39
  raise InvalidSearchTypeError
53
40
  end
54
- req += '&Phrase='
41
+ req += "&Phrase="
55
42
 
56
43
  req += CGI.escape(criterion)
57
44
  p req if $DEBUG
@@ -61,16 +48,16 @@ module Alexandria
61
48
  return to_books(data).pop
62
49
  else
63
50
  results = []
64
- to_books(data).each { |book|
51
+ to_books(data).each do |book|
65
52
  results << book
66
- }
53
+ end
67
54
  while /Suivant/ =~ data
68
- md = /Enteterouge\">([\d]*)<\/b>/.match(data)
55
+ md = %r{Enteterouge\">([\d]*)</b>}.match(data)
69
56
  num = md[1].to_i + 1
70
- data = transport.get(URI.parse(req + '&PageActuelle=' + num.to_s))
71
- to_books(data).each { |book|
57
+ data = transport.get(URI.parse(req + "&PageActuelle=" + num.to_s))
58
+ to_books(data).each do |book|
72
59
  results << book
73
- }
60
+ end
74
61
  end
75
62
  return results
76
63
  end
@@ -80,72 +67,72 @@ module Alexandria
80
67
  end
81
68
 
82
69
  def url(book)
83
- 'http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=' \
84
- '&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=' + book.isbn
70
+ "http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=" \
71
+ "&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=" + book.isbn
85
72
  end
86
73
 
87
74
  private
88
75
 
89
76
  NO_BOOKS_FOUND_REGEXP =
90
- /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong>/.freeze
77
+ %r{<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s</strong>}.freeze
91
78
  HYPERLINK_SCAN_REGEXP =
92
- /"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/.
93
- freeze
79
+ %r{"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)</strong></a><br>}
80
+ .freeze
94
81
 
95
82
  def to_books(data)
96
83
  data = CGI.unescapeHTML(data)
97
- data = data.encode('UTF-8')
98
- raise NoResultsError if data =~ NO_BOOKS_FOUND_REGEXP
84
+ data = data.encode("UTF-8")
85
+ raise NoResultsError if NO_BOOKS_FOUND_REGEXP.match?(data)
99
86
 
100
87
  titles = []
101
- data.scan(HYPERLINK_SCAN_REGEXP).each { |md|
88
+ data.scan(HYPERLINK_SCAN_REGEXP).each do |md|
102
89
  titles << md[1].strip
103
- }
90
+ end
104
91
  raise if titles.empty?
105
92
 
106
93
  authors = []
107
- data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each { |md|
94
+ data.scan(%r{Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)</i>}).each do |md|
108
95
  authors2 = []
109
- for author in md[0].split(' ')
96
+ md[0].split(" ").each do |author|
110
97
  authors2 << author.strip
111
98
  end
112
99
  authors << authors2
113
- }
100
+ end
114
101
  raise if authors.empty?
115
102
 
116
103
  isbns = []
117
- data.scan(/ISBN : ?<\/td><td>(\d+)/).each { |md|
104
+ data.scan(%r{ISBN : ?</td><td>(\d+)}).each do |md|
118
105
  isbns << md[0].strip
119
- }
106
+ end
120
107
  raise if isbns.empty?
121
108
 
122
109
  editions = []
123
110
  publish_years = []
124
- data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each { |md|
111
+ data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each do |md|
125
112
  editions << md[0].strip
126
113
  publish_years << md[0].strip.split(/-/)[0].to_i
127
- }
114
+ end
128
115
  raise if editions.empty? || publish_years.empty?
129
116
 
130
117
  publishers = []
131
- data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each { |md|
118
+ data.scan(%r{diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)</span><br>}).each do |md|
132
119
  publishers << md[0].strip
133
- }
120
+ end
134
121
  raise if publishers.empty?
135
122
 
136
123
  book_covers = []
137
- data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))
138
- |\/francais\/suggestion\/images\/livre\/livre.gif)/x).each { |md|
124
+ data.scan(%r{(/ImagesEditeurs/[\d]*/([\dX]*-f.(jpg|gif))
125
+ |/francais/suggestion/images/livre/livre.gif)}x).each do |md|
139
126
  book_covers << BASE_URI + md[0].strip
140
- }
127
+ end
141
128
  raise if book_covers.empty?
142
129
 
143
130
  books = []
144
- titles.each_with_index { |title, i|
131
+ titles.each_with_index do |title, i|
145
132
  books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
146
133
  book_covers[i]]
147
134
  # print books
148
- }
135
+ end
149
136
  raise if books.empty?
150
137
 
151
138
  books