alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (C) 2009 Cathal Mc Ginley
2
4
  # Copyright (C) 2014 Matijs van Zuijlen
3
5
  #
@@ -22,7 +24,7 @@ module Alexandria
22
24
  class WWWAgent
23
25
  def initialize
24
26
  user_agent = "Ruby #{RUBY_VERSION} #{Alexandria::TITLE}/#{Alexandria::VERSION}"
25
- @extra_request_headers = { 'User-Agent' => user_agent }
27
+ @extra_request_headers = { "User-Agent" => user_agent }
26
28
  end
27
29
 
28
30
  def self.transport
@@ -36,18 +38,17 @@ module Alexandria
36
38
  @extra_request_headers.each_pair do |header_name, value|
37
39
  req.add_field(header_name, value)
38
40
  end
39
- res = WWWAgent.transport.start(uri.host, uri.port) { |http|
41
+ WWWAgent.transport.start(uri.host, uri.port) do |http|
40
42
  http.request(req)
41
- }
42
- res
43
+ end
43
44
  end
44
45
 
45
46
  def language=(lang)
46
- @extra_request_headers['Accept-Language'] = lang.to_s
47
+ @extra_request_headers["Accept-Language"] = lang.to_s
47
48
  end
48
49
 
49
50
  def user_agent=(agent_string)
50
- @extra_request_headers['User-Agent'] = agent_string
51
+ @extra_request_headers["User-Agent"] = agent_string
51
52
  end
52
53
  end
53
54
  end
@@ -1,37 +1,24 @@
1
- # Copyright (C) 2004-2006 Laurent Sansonetti
2
- # Copyright (C) 2011 Cathal Mc Ginley
3
- # Copyright (C) 2011, 2016 Matijs van Zuijlen
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.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
14
4
  #
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
- require 'singleton'
21
- require 'set'
22
- require 'alexandria/default_preferences'
7
+ require "singleton"
8
+ require "set"
9
+ require "alexandria/default_preferences"
23
10
 
24
11
  module Alexandria
25
12
  class Preferences
26
13
  include Singleton
27
14
  include Logging
28
15
 
29
- APP_DIR = '/apps/alexandria'.freeze
30
- HTTP_PROXY_DIR = '/system/http_proxy'.freeze
31
- HTTP_PROXY_MODE = '/system/proxy/mode'.freeze
32
- URL_HANDLERS_DIR = '/desktop/gnome/url-handlers'.freeze
16
+ APP_DIR = "/apps/alexandria"
17
+ HTTP_PROXY_DIR = "/system/http_proxy"
18
+ HTTP_PROXY_MODE = "/system/proxy/mode"
19
+ URL_HANDLERS_DIR = "/desktop/gnome/url-handlers"
33
20
 
34
- GCONFTOOL = 'gconftool-2'.freeze
21
+ GCONFTOOL = "gconftool-2"
35
22
 
36
23
  def initialize
37
24
  @alexandria_settings = {}
@@ -59,38 +46,35 @@ module Alexandria
59
46
  end
60
47
 
61
48
  def save!
62
- log.debug { 'preferences save!' }
49
+ log.debug { "preferences save!" }
63
50
  @changed_settings.each do |variable_name|
64
- log.debug { "saving preference #{variable_name} / #{@alexandria_settings[variable_name].class}" }
51
+ log.debug do
52
+ klass = @alexandria_settings[variable_name].class
53
+ "saving preference #{variable_name} / #{klass}"
54
+ end
65
55
  generic_save_setting(variable_name, @alexandria_settings[variable_name])
66
56
  end
67
57
  @changed_settings.clear
68
58
  end
69
59
 
70
- def method_missing(id, *args)
71
- method = id.id2name
72
- if (match = /(.*)=$/.match(method))
73
- if args.length != 1
74
- raise "Set method #{method} should be called with " \
75
- "only one argument (was called with #{args.length})"
76
- end
77
- variable_name = match[1]
78
- new_value = args.first
79
- generic_setter(variable_name, new_value)
80
- else
81
- unless args.empty?
82
- raise "Get method #{method} should be called " \
83
- "without argument (was called with #{args.length})"
84
- end
85
- generic_getter(method)
86
- end
87
- end
88
-
89
60
  def remove_preference(variable_name)
90
61
  @alexandria_settings.delete(variable_name)
91
62
  @changed_settings << variable_name
92
63
  end
93
64
 
65
+ DEFAULT_VALUES.each_key do |var|
66
+ define_method(var) { generic_getter var }
67
+ define_method("#{var}=") { |val| generic_setter var, val }
68
+ end
69
+
70
+ def get_variable(variable_name)
71
+ generic_getter(variable_name.to_s)
72
+ end
73
+
74
+ def set_variable(variable_name, value)
75
+ generic_setter(variable_name.to_s, value)
76
+ end
77
+
94
78
  private
95
79
 
96
80
  ##
@@ -116,13 +100,11 @@ module Alexandria
116
100
  end
117
101
  old_value = @alexandria_settings[variable_name]
118
102
  @alexandria_settings[variable_name] = new_value
119
- unless new_value == old_value
120
- @changed_settings << variable_name
121
- end
103
+ @changed_settings << variable_name unless new_value == old_value
122
104
  end
123
105
 
124
106
  def generic_save_setting(variable_name, new_value)
125
- var_path = APP_DIR + '/' + variable_name
107
+ var_path = APP_DIR + "/" + variable_name
126
108
  if new_value.is_a?(Array)
127
109
  # when setting array, first remove nil elements (fixing #9007)
128
110
  new_value.compact!
@@ -132,17 +114,17 @@ module Alexandria
132
114
  # set list value
133
115
  exec_gconf_set_list(var_path, new_value)
134
116
  end
117
+ elsif new_value.nil?
118
+ exec_gconf_unset(variable_name)
135
119
  else
136
120
  # set non-list value
137
- if new_value.nil?
138
- exec_gconf_unset(variable_name)
139
- else
140
- exec_gconf_set(var_path, new_value)
141
- end
121
+ exec_gconf_set(var_path, new_value)
142
122
  end
143
- rescue => ex
123
+ rescue StandardError => ex
144
124
  log.debug { new_value.inspect }
145
- log.error { "Could not set GConf setting #{variable_name} to value: #{new_value.inspect}" }
125
+ log.error do
126
+ "Could not set GConf setting #{variable_name} to value: #{new_value.inspect}"
127
+ end
146
128
  log << ex.message
147
129
  log << ex
148
130
  end
@@ -152,14 +134,15 @@ module Alexandria
152
134
  ##
153
135
 
154
136
  def get_gconf_type(value)
155
- if value.is_a?(String)
156
- 'string'
157
- elsif value.is_a?(Integer)
158
- 'int'
159
- elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
160
- 'bool'
137
+ case value
138
+ when String
139
+ "string"
140
+ when Integer
141
+ "int"
142
+ when TrueClass, FalseClass
143
+ "bool"
161
144
  else
162
- 'string'
145
+ "string"
163
146
  end
164
147
  end
165
148
 
@@ -167,7 +150,7 @@ module Alexandria
167
150
  # NOTE we must check between list and pair...
168
151
 
169
152
  list_type = get_gconf_type(new_list.first)
170
- if list_type == 'int' && new_list.size == 2
153
+ if list_type == "int" && new_list.size == 2
171
154
  # treat this as a pair of int
172
155
  a = new_list[0]
173
156
  b = new_list[1]
@@ -180,31 +163,29 @@ module Alexandria
180
163
  end
181
164
 
182
165
  def make_list_string(list)
183
- if get_gconf_type(list.first) == 'string'
184
- list.map! { |x| x.gsub(/\"/, '\\"') }
185
- end
186
- contents = list.join(',')
187
- '[' + contents + ']'
166
+ list.map! { |x| x.gsub(/"/, '\\"') } if get_gconf_type(list.first) == "string"
167
+ contents = list.join(",")
168
+ "[" + contents + "]"
188
169
  end
189
170
 
190
171
  def exec_gconf_set(var_path, new_value)
191
- if /cols_width/ =~ var_path
192
- puts new_value
172
+ if /cols_width/.match?(var_path)
173
+ log.debug { new_value }
193
174
 
194
175
  # new_value = {}
195
176
  end
196
177
  type = get_gconf_type(new_value)
197
178
  value_str = new_value
198
179
  if new_value.is_a? String
199
- new_value.gsub!(/\"/, '\\"')
180
+ new_value = new_value.gsub(/"/, '\\"')
200
181
  value_str = "\"#{new_value}\""
201
182
  end
202
- puts value_str if /cols_width/ =~ var_path
183
+ log.debug { value_str } if /cols_width/.match?(var_path)
203
184
  `gconftool-2 --type #{type} --set #{var_path} #{value_str}`
204
185
  end
205
186
 
206
187
  def exec_gconf_unset(variable_name)
207
- `#{GCONFTOOL} --unset #{APP_DIR + '/' + variable_name}`
188
+ `#{GCONFTOOL} --unset #{APP_DIR + "/" + variable_name}`
208
189
  end
209
190
 
210
191
  ##
@@ -224,14 +205,14 @@ module Alexandria
224
205
  def load_http_proxy_settings
225
206
  http_proxy_vars = `#{GCONFTOOL} --recursive-list #{HTTP_PROXY_DIR}`
226
207
  http_proxy = gconftool_values_to_hash(http_proxy_vars)
227
- if http_proxy['use_http_proxy']
208
+ if http_proxy["use_http_proxy"]
228
209
  proxy_mode = `#{GCONFTOOL} --get #{HTTP_PROXY_MODE}`.chomp
229
- if proxy_mode == 'manual'
210
+ if proxy_mode == "manual"
230
211
  @use_http_proxy = true
231
- @proxy_host = http_proxy['host']
232
- @proxy_port = http_proxy['port']
233
- @proxy_user = http_proxy['authentication_user']
234
- @proxy_password = http_proxy['authentication_n_password']
212
+ @proxy_host = http_proxy["host"]
213
+ @proxy_port = http_proxy["port"]
214
+ @proxy_user = http_proxy["authentication_user"]
215
+ @proxy_password = http_proxy["authentication_n_password"]
235
216
  end
236
217
  end
237
218
  @http_proxy_loaded = true
@@ -256,20 +237,21 @@ module Alexandria
256
237
  # gconftool. This is not fool-proof, but it *does* work for the
257
238
  # range of values used by Alexandria.
258
239
  def discriminate(value)
259
- if value == 'true' # bool
240
+ case value
241
+ when "true" # bool
260
242
  true
261
- elsif value == 'false' # bool
243
+ when "false" # bool
262
244
  false
263
- elsif value =~ /^[0-9]+$/ # int
245
+ when /^[0-9]+$/ # int
264
246
  value.to_i
265
- elsif value =~ /^\[(.*)\]$/ # list (assume of type String)
266
- Regexp.last_match[1].split(',')
267
- elsif value =~ /^\((.*)\)$/ # pair (assume of type int)
247
+ when /^\[(.*)\]$/ # list (assume of type String)
248
+ Regexp.last_match[1].split(",")
249
+ when /^\((.*)\)$/ # pair (assume of type int)
268
250
  begin
269
- pair = Regexp.last_match[1].split(',')
270
- return [discriminate(pair.first), discriminate(pair.last)]
271
- rescue
272
- return [0, 0]
251
+ pair = Regexp.last_match[1].split(",")
252
+ [discriminate(pair.first), discriminate(pair.last)]
253
+ rescue StandardError
254
+ [0, 0]
273
255
  end
274
256
  else
275
257
  value # string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (C) 2005-2006 Christopher Cyll
2
4
  # Copyright (C) 2014-2016 Matijs van Zuijlen
3
5
  #
@@ -38,8 +40,8 @@ module Alexandria
38
40
  registry.find { |scanner| scanner.name == name }
39
41
  end
40
42
 
41
- def self.each_scanner
42
- registry.each { |scanner| yield scanner }
43
+ def self.each_scanner(&block)
44
+ registry.each(&block)
43
45
  end
44
46
 
45
47
  private_class_method :registry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (C) 2005-2006 Christopher Cyll
2
4
  # Copyright (C) 2011 Matijs van Zuijlen
3
5
  #
@@ -16,28 +18,30 @@
16
18
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
19
  # Fifth Floor, Boston, MA 02110-1301 USA.
18
20
 
19
- require 'alexandria/scanners'
21
+ require "alexandria/scanners"
20
22
 
21
23
  module Alexandria
22
24
  module Scanners
23
25
  class CueCat
24
- include Alexandria::Logging
26
+ include Logging
25
27
 
26
28
  def name
27
- 'CueCat'
29
+ "CueCat"
28
30
  end
29
31
 
30
32
  def display_name
31
- 'CueCat'
33
+ "CueCat"
32
34
  end
33
35
 
34
36
  # Checks if data looks like cuecat input
35
37
  def match?(data)
36
- data.chomp!
37
- return false if data[-1] != '.'
38
- fields = data.split('.')
38
+ data = data.chomp
39
+ return false if data[-1] != "."
40
+
41
+ fields = data.split(".")
39
42
  return false if fields.size != 4
40
43
  return false if fields[2].size != 4
44
+
41
45
  true
42
46
  end
43
47
 
@@ -45,14 +49,14 @@ module Alexandria
45
49
  # The following code is adapted from Skip Rosebaugh's public
46
50
  # domain perl implementation.
47
51
  def decode(data)
48
- data.chomp!
49
- fields = data.split('.')
52
+ data = data.chomp
53
+ fields = data.split(".")
50
54
  fields.shift # First part is gibberish
51
55
  fields.shift # Second part is cuecat serial number
52
56
  type, code = fields.map { |field| decode_field(field) }
53
57
 
54
- if type == 'IB5'
55
- type = 'IBN'
58
+ if type == "IB5"
59
+ type = "IBN"
56
60
  code = code[0, 13]
57
61
  end
58
62
 
@@ -60,33 +64,33 @@ module Alexandria
60
64
  if Library.valid_upc? code
61
65
  isbn13 = Library.canonicalise_ean(code)
62
66
  code = isbn13
63
- type = 'IBN'
67
+ type = "IBN"
64
68
  end
65
- rescue
69
+ rescue StandardError
66
70
  log.debug { "Cannot translate UPC (#{type}) code #{code} to ISBN" }
67
71
  end
68
72
 
69
- return code if type == 'IBN'
73
+ return code if type == "IBN"
70
74
 
71
- raise "Don't know how to handle type #{type} (barcode: #{code})"
75
+ raise format(_("Don't know how to handle type %<type>s (barcode: %<code>s)"),
76
+ type: type, code: code)
72
77
  end
73
78
 
74
79
  private
75
80
 
76
81
  def decode_field(encoded)
77
- seq = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-'
82
+ seq = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-"
78
83
 
79
84
  chars = encoded.split(//)
80
85
  values = chars.map { |c| seq.index(c) }
81
86
 
82
87
  padding = pad(values)
83
88
  result = calc(values)
84
- result = result[0, result.length - padding]
85
- result
89
+ result[0, result.length - padding]
86
90
  end
87
91
 
88
92
  def calc(values)
89
- result = ''
93
+ result = ""
90
94
  until values.empty?
91
95
  num = ((values[0] << 6 | values[1]) << 6 | values[2]) << 6 | values[3]
92
96
  result += ((num >> 16) ^ 67).chr
@@ -102,7 +106,7 @@ module Alexandria
102
106
  length = array.length % 4
103
107
 
104
108
  if length.nonzero?
105
- raise 'Error parsing CueCat input' if length == 1
109
+ raise _("Error parsing CueCat input") if length == 1
106
110
 
107
111
  length = 4 - length
108
112
  length.times { array.push(0) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (C) 2005-2006 Christopher Cyll
2
4
  # Copyright (C) 2008 Cathal Mc Ginley
3
5
  #
@@ -16,7 +18,7 @@
16
18
  # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
19
  # Fifth Floor, Boston, MA 02110-1301 USA.
18
20
 
19
- require 'alexandria/scanners'
21
+ require "alexandria/scanners"
20
22
 
21
23
  module Alexandria
22
24
  module Scanners
@@ -25,28 +27,28 @@ module Alexandria
25
27
  # like this.)
26
28
  class KeyboardWedge
27
29
  def name
28
- 'KeyboardWedge'
30
+ "KeyboardWedge"
29
31
  end
30
32
 
31
33
  def display_name
32
- 'Keyboard Wedge'
34
+ "Keyboard Wedge"
33
35
  end
34
36
 
35
37
  # Checks if data looks like a completed scan
36
38
  def match?(data)
37
- data.gsub!(/\s/, '')
39
+ data.gsub!(/\s/, "")
38
40
  (data =~ /[0-9]{12,18}/) || (data =~ /[0-9]{9}[0-9Xx]/)
39
41
  end
40
42
 
41
43
  # Gets the essential 13-digits from an ISBN barcode (EAN-13)
42
44
  def decode(data)
43
- data.gsub!(/\s/, '')
45
+ data.gsub!(/\s/, "")
44
46
  if data.length == 10
45
- return data
47
+ data
46
48
  elsif data.length >= 13
47
- return data[0, 13]
49
+ data[0, 13]
48
50
  else
49
- raise "Unknown scan data #{data}"
51
+ raise format(_("Unknown scan data %s<data>"), data: data)
50
52
  end
51
53
  end
52
54
  end