alexandria-book-collection-manager 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +4 -1
  4. data/.rubocop.yml +51 -29
  5. data/.rubocop_todo.yml +33 -155
  6. data/.simplecov +5 -2
  7. data/.travis.yml +10 -4
  8. data/CHANGELOG.md +19 -0
  9. data/INSTALL.md +23 -11
  10. data/README.md +36 -35
  11. data/Rakefile +7 -5
  12. data/alexandria-book-collection-manager.gemspec +8 -3
  13. data/doc/dependency_decisions.yml +22 -3
  14. data/lib/alexandria.rb +2 -2
  15. data/lib/alexandria/book_providers.rb +47 -49
  16. data/lib/alexandria/book_providers/adlibris.rb +8 -13
  17. data/lib/alexandria/book_providers/amazon_aws.rb +47 -60
  18. data/lib/alexandria/book_providers/amazon_ecs_util.rb +283 -298
  19. data/lib/alexandria/book_providers/barnes_and_noble.rb +8 -8
  20. data/lib/alexandria/book_providers/douban.rb +2 -2
  21. data/lib/alexandria/book_providers/proxis.rb +12 -11
  22. data/lib/alexandria/book_providers/pseudomarc.rb +60 -70
  23. data/lib/alexandria/book_providers/siciliano.rb +5 -6
  24. data/lib/alexandria/book_providers/thalia.rb +8 -9
  25. data/lib/alexandria/book_providers/worldcat.rb +25 -31
  26. data/lib/alexandria/book_providers/z3950.rb +62 -69
  27. data/lib/alexandria/default_preferences.rb +37 -0
  28. data/lib/alexandria/execution_queue.rb +13 -12
  29. data/lib/alexandria/export_library.rb +4 -8
  30. data/lib/alexandria/import_library.rb +38 -62
  31. data/lib/alexandria/import_library_csv.rb +16 -16
  32. data/lib/alexandria/library_sort_order.rb +3 -1
  33. data/lib/alexandria/library_store.rb +16 -16
  34. data/lib/alexandria/logging.rb +4 -8
  35. data/lib/alexandria/models/book.rb +2 -2
  36. data/lib/alexandria/models/library.rb +18 -14
  37. data/lib/alexandria/net.rb +1 -2
  38. data/lib/alexandria/preferences.rb +27 -31
  39. data/lib/alexandria/scanners.rb +2 -2
  40. data/lib/alexandria/scanners/cue_cat.rb +5 -5
  41. data/lib/alexandria/scanners/keyboard.rb +1 -1
  42. data/lib/alexandria/smart_library.rb +22 -26
  43. data/lib/alexandria/ui.rb +7 -7
  44. data/lib/alexandria/ui/about_dialog.rb +1 -1
  45. data/lib/alexandria/ui/acquire_dialog.rb +9 -10
  46. data/lib/alexandria/ui/alert_dialog.rb +34 -19
  47. data/lib/alexandria/ui/bad_isbns_dialog.rb +13 -9
  48. data/lib/alexandria/ui/barcode_animation.rb +5 -5
  49. data/lib/alexandria/ui/book_properties_dialog.rb +2 -2
  50. data/lib/alexandria/ui/book_properties_dialog_base.rb +23 -17
  51. data/lib/alexandria/ui/callbacks.rb +141 -120
  52. data/lib/alexandria/ui/completion_models.rb +1 -1
  53. data/lib/alexandria/ui/confirm_erase_dialog.rb +1 -1
  54. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +1 -1
  55. data/lib/alexandria/ui/error_dialog.rb +1 -1
  56. data/lib/alexandria/ui/export_dialog.rb +13 -15
  57. data/lib/alexandria/ui/icons.rb +34 -40
  58. data/lib/alexandria/ui/iconview_tooltips.rb +40 -53
  59. data/lib/alexandria/ui/import_dialog.rb +48 -47
  60. data/lib/alexandria/ui/init.rb +3 -2
  61. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +2 -2
  62. data/lib/alexandria/ui/libraries_combo.rb +10 -9
  63. data/lib/alexandria/ui/listview.rb +5 -6
  64. data/lib/alexandria/ui/main_app.rb +2 -2
  65. data/lib/alexandria/ui/multi_drag_treeview.rb +4 -6
  66. data/lib/alexandria/ui/new_book_dialog.rb +52 -52
  67. data/lib/alexandria/ui/new_provider_dialog.rb +12 -11
  68. data/lib/alexandria/ui/new_smart_library_dialog.rb +39 -27
  69. data/lib/alexandria/ui/preferences_dialog.rb +23 -82
  70. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +9 -5
  71. data/lib/alexandria/ui/provider_preferences_dialog.rb +5 -5
  72. data/lib/alexandria/ui/really_delete_dialog.rb +1 -1
  73. data/lib/alexandria/ui/sidepane_manager.rb +35 -37
  74. data/lib/alexandria/ui/skip_entry_dialog.rb +3 -2
  75. data/lib/alexandria/ui/smart_library_properties_dialog.rb +35 -36
  76. data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +59 -138
  77. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  78. data/lib/alexandria/ui/sound.rb +4 -6
  79. data/lib/alexandria/ui/ui_manager.rb +62 -64
  80. data/lib/alexandria/version.rb +2 -2
  81. data/lib/alexandria/web_themes.rb +15 -15
  82. data/po/cs.po +991 -874
  83. data/po/cy.po +957 -870
  84. data/po/de.po +991 -866
  85. data/po/el.po +987 -863
  86. data/po/es.po +986 -862
  87. data/po/fr.po +988 -868
  88. data/po/ga.po +910 -822
  89. data/po/gl.po +983 -863
  90. data/po/it.po +984 -862
  91. data/po/ja.po +969 -849
  92. data/po/mk.po +983 -859
  93. data/po/nb.po +982 -862
  94. data/po/nl.po +992 -869
  95. data/po/pl.po +1018 -963
  96. data/po/pt.po +983 -852
  97. data/po/pt_BR.po +983 -863
  98. data/po/ru.po +992 -869
  99. data/po/sk.po +986 -864
  100. data/po/sv.po +980 -860
  101. data/po/uk.po +975 -861
  102. data/po/zh_TW.po +974 -854
  103. data/share/alexandria/glade/main_app__builder.glade +6 -21
  104. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  105. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  106. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  107. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  108. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  109. data/spec/alexandria/book_providers_spec.rb +73 -129
  110. data/spec/alexandria/console_spec.rb +0 -5
  111. data/spec/alexandria/export_library_spec.rb +27 -38
  112. data/spec/alexandria/library_spec.rb +56 -44
  113. data/spec/alexandria/preferences_spec.rb +29 -3
  114. data/spec/alexandria/scanners/cue_cat_spec.rb +1 -1
  115. data/spec/alexandria/ui/about_dialog_spec.rb +1 -1
  116. data/spec/alexandria/ui/acquire_dialog_spec.rb +1 -1
  117. data/spec/alexandria/ui/alert_dialog_spec.rb +1 -1
  118. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +1 -1
  119. data/spec/alexandria/ui/book_properties_dialog_spec.rb +1 -1
  120. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +1 -1
  121. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +1 -1
  122. data/spec/alexandria/ui/error_dialog_spec.rb +1 -1
  123. data/spec/alexandria/ui/export_dialog_spec.rb +1 -1
  124. data/spec/alexandria/ui/icons_spec.rb +26 -0
  125. data/spec/alexandria/ui/iconview_spec.rb +1 -1
  126. data/spec/alexandria/ui/import_dialog_spec.rb +30 -3
  127. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +1 -1
  128. data/spec/alexandria/ui/main_app_spec.rb +1 -1
  129. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +1 -1
  130. data/spec/alexandria/ui/new_provider_dialog_spec.rb +19 -3
  131. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +28 -3
  132. data/spec/alexandria/ui/preferences_dialog_spec.rb +1 -1
  133. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +23 -8
  134. data/spec/alexandria/ui/really_delete_dialog_spec.rb +1 -1
  135. data/spec/alexandria/ui/sidepane_manager_spec.rb +2 -2
  136. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +1 -1
  137. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +21 -7
  138. data/spec/alexandria/ui/ui_manager_spec.rb +39 -2
  139. data/spec/spec_helper.rb +46 -3
  140. data/tasks/spec.rake +3 -5
  141. data/util/rake/fileinstall.rb +12 -11
  142. metadata +82 -10
  143. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
  144. data/spec/alexandria/utilities_spec.rb +0 -52
@@ -72,8 +72,7 @@ module Alexandria
72
72
  additional.split(",").each do |add|
73
73
  authors << normalize(add)
74
74
  end
75
- isbn = row[@isbn] # TODO: canonicalize_ean...
76
- isbn = Library.canonicalise_ean(isbn) if isbn
75
+ isbn = Library.canonicalise_ean(row[@isbn])
77
76
  publisher = normalize(row[@publisher])
78
77
  year = row[@publishing_year].to_i
79
78
  edition = normalize(row[@edition])
@@ -95,12 +94,13 @@ module Alexandria
95
94
  book.redd = true
96
95
  end
97
96
  if row[@mainshelf]
98
- if row[@mainshelf] == "read"
97
+ case row[@mainshelf]
98
+ when "read"
99
99
  book.redd = true
100
- elsif row[@mainshelf] == "to-read"
100
+ when "to-read"
101
101
  book.redd = false
102
102
  book.tags = ["to read"]
103
- elsif row[@mainshelf] == "currently-reading"
103
+ when "currently-reading"
104
104
  book.redd = false
105
105
  book.tags = ["currently reading"]
106
106
  end
@@ -112,7 +112,7 @@ module Alexandria
112
112
  book.tags << tag unless book.tags.include? tag
113
113
  end
114
114
  end
115
- puts "Goodreads loading #{book.title}" if $DEBUG
115
+ log.debug { "Goodreads loading #{book.title}" }
116
116
  book
117
117
  end
118
118
  end
@@ -146,7 +146,7 @@ module Alexandria
146
146
  # sometimes "Publisher (YEAR), Edition: NUM, Binding, NUM pages"
147
147
  publisher_info = normalize(row[@publisher_info])
148
148
  publisher = publisher_info
149
- publisher = Regexp.last_match[1] if publisher_info =~ /([^\(]+)\(/
149
+ publisher = Regexp.last_match[1] if publisher_info =~ /([^(]+)\(/
150
150
  edition = publisher_info # binding
151
151
  edition_info = publisher_info.split(",")
152
152
  edition = publisher_info.split(",")[-2] if edition_info.size >= 3
@@ -169,7 +169,7 @@ module Alexandria
169
169
  end
170
170
  end
171
171
 
172
- puts "LibraryThing loading #{book.title}" if $DEBUG
172
+ log.debug { "LibraryThing loading #{book.title}" }
173
173
  book
174
174
  end
175
175
  end
@@ -183,20 +183,20 @@ module Alexandria
183
183
  is_librarything = false
184
184
  is_goodreads = false
185
185
  header.each do |head|
186
- if head == "'PUBLICATION INFO'"
186
+ case head
187
+ when "'PUBLICATION INFO'"
187
188
  is_librarything = true
188
189
  break
189
- elsif head == "Year Published"
190
+ when "Year Published"
190
191
  is_goodreads = true
191
192
  break
192
193
  end
193
194
  end
194
- if is_librarything
195
- return LibraryThingCSVImport.new(header)
196
- elsif is_goodreads
197
- return GoodreadsCSVImport.new(header)
198
- end
199
- raise "Not Recognized" unless is_librarything || is_goodreads
195
+
196
+ return LibraryThingCSVImport.new(header) if is_librarything
197
+ return GoodreadsCSVImport.new(header) if is_goodreads
198
+
199
+ raise _("Not Recognized") unless is_librarything || is_goodreads
200
200
  end
201
201
  end
202
202
  end
@@ -29,7 +29,9 @@ module Alexandria
29
29
  end
30
30
 
31
31
  class Unsorted < LibrarySortOrder
32
- def initialize; end
32
+ def initialize
33
+ super(nil, nil)
34
+ end
33
35
 
34
36
  def sort(library)
35
37
  library
@@ -9,7 +9,7 @@ module Alexandria
9
9
  include Logging
10
10
 
11
11
  FIX_BIGNUM_REGEX =
12
- %r{loaned_since:\s*(\!ruby/object\:Bignum\s*)?(\d+)\n}.freeze
12
+ %r{loaned_since:\s*(!ruby/object:Bignum\s*)?(\d+)\n}.freeze
13
13
 
14
14
  include GetText
15
15
  bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
@@ -23,7 +23,7 @@ module Alexandria
23
23
  begin
24
24
  Dir.entries(library_dir).each do |file|
25
25
  # Skip hidden files.
26
- next if /^\./.match?(file)
26
+ next if file.start_with?(".")
27
27
  # Skip non-directory files.
28
28
  next unless File.stat(File.join(library_dir, file)).directory?
29
29
 
@@ -64,7 +64,7 @@ module Alexandria
64
64
  old_isbn = book.isbn
65
65
  old_pub_year = book.publishing_year
66
66
  begin
67
- raise "Not a book: #{book.inspect}" unless book.is_a?(Book)
67
+ raise format(_("Not a book: %<book>s"), book.inspect) unless book.is_a?(Book)
68
68
 
69
69
  ean = Library.canonicalise_ean(book.isbn)
70
70
  book.isbn = ean if ean
@@ -74,16 +74,18 @@ module Alexandria
74
74
  end
75
75
 
76
76
  # Or if isbn has changed
77
- raise "#{test[1]} isbn is not okay" unless book.isbn == old_isbn
77
+ unless book.isbn == old_isbn
78
+ raise format(_("%<file>s isbn is not okay"), file: test[1])
79
+ end
78
80
 
79
81
  # Re-save book if Alexandria::DATA_VERSION changes
80
82
  unless book.version == Alexandria::DATA_VERSION
81
- raise "#{test[1]} version is not okay"
83
+ raise format(_("%<file>s version is not okay"), file: test[1])
82
84
  end
83
85
 
84
86
  # Or if publishing year has changed
85
87
  unless book.publishing_year == old_pub_year
86
- raise "#{test[1]} pub year is not okay"
88
+ raise format(_("%<file>s pub year is not okay"), file: test[1])
87
89
  end
88
90
 
89
91
  # ruined_books << [book, book.isbn, library]
@@ -92,13 +94,11 @@ module Alexandria
92
94
  ## TODO copy cover image file, if necessary
93
95
  # due to #26909 cover files for books without ISBN are re-saved as
94
96
  # "g#{ident}.cover"
95
- if book.isbn.nil? || book.isbn.empty?
96
- if File.exist? library.old_cover(book)
97
- log.debug do
98
- "#{library.name}; book #{book.title} has no ISBN, fixing cover image"
99
- end
100
- FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
97
+ if (book.isbn.nil? || book.isbn.empty?) && File.exist?(library.old_cover(book))
98
+ log.debug do
99
+ "#{library.name}; book #{book.title} has no ISBN, fixing cover image"
101
100
  end
101
+ FileUtils::Verbose.mv(library.old_cover(book), library.cover(book))
102
102
  end
103
103
 
104
104
  library << book
@@ -198,14 +198,14 @@ module Alexandria
198
198
  if (md = FIX_BIGNUM_REGEX.match(text))
199
199
  new_yaml = Time.at(md[2].to_i).to_yaml
200
200
  # Remove the "---" prefix.
201
- new_yaml.sub!(/^\s*\-+\s*/, "")
201
+ new_yaml.sub!(/^\s*-+\s*/, "")
202
202
  text.sub!(md[0], "loaned_since: #{new_yaml}\n")
203
203
  end
204
204
 
205
205
  # TODO: Ensure book loading passes through Book#initialize
206
206
  book = YAML.safe_load(text, permitted_classes: [Book, Time])
207
207
 
208
- unless book.isbn.class == String
208
+ unless book.isbn.instance_of? String
209
209
  # HACK
210
210
  md = /isbn: (.+)/.match(text)
211
211
  if md
@@ -215,7 +215,7 @@ module Alexandria
215
215
  end
216
216
 
217
217
  # another HACK of the same type as above
218
- unless book.saved_ident.class == String
218
+ unless book.saved_ident.instance_of? String
219
219
 
220
220
  md2 = /saved_ident: (.+)/.match(text)
221
221
  if md2
@@ -224,7 +224,7 @@ module Alexandria
224
224
  book.saved_ident = string_saved_ident
225
225
  end
226
226
  end
227
- if (book.isbn.class == String) && book.isbn.empty?
227
+ if (book.isbn.instance_of? String) && book.isbn.empty?
228
228
  book.isbn = nil # save trouble later
229
229
  end
230
230
  book
@@ -25,7 +25,7 @@ module Alexandria
25
25
  # A Logger subclass which accepts a source for log messages
26
26
  # in order to improve legibility of the logs.
27
27
  # The source should usually be +self+, whether that be a Class, Module
28
- # or Object. A LoggerWrapper can be used to simplify this procedure.
28
+ # or Object. A LogWrapper can be used to simplify this procedure.
29
29
  class Logger < ::Logger
30
30
  def add(severity, message = nil, source = nil, progname = nil, &block)
31
31
  return super(severity, message, progname, &block) if source.nil?
@@ -118,7 +118,7 @@ module Alexandria
118
118
  module Logging
119
119
  module ClassMethods
120
120
  def log
121
- @log_wrapper ||= LogWrapper.new(Alexandria.log, self)
121
+ @log ||= LogWrapper.new(Alexandria.log, self)
122
122
  end
123
123
  end
124
124
 
@@ -127,15 +127,13 @@ module Alexandria
127
127
  end
128
128
 
129
129
  def log
130
- @log_wrapper ||= LogWrapper.new(Alexandria.log, self)
130
+ @log ||= LogWrapper.new(Alexandria.log, self)
131
131
  end
132
132
  end
133
133
 
134
- private
135
-
136
134
  # Creates the Logger for Alexandria
137
135
  def self.create_logger
138
- logger = Alexandria::Logger.new(STDERR)
136
+ logger = Alexandria::Logger.new($stderr)
139
137
 
140
138
  level = ENV["LOGLEVEL"] ? ENV["LOGLEVEL"].intern : nil
141
139
  if [:FATAL, :ERROR, :WARN, :INFO, :DEBUG].include? level
@@ -150,8 +148,6 @@ module Alexandria
150
148
 
151
149
  @@logger = create_logger
152
150
 
153
- public
154
-
155
151
  # Returns the Logger for Alexandria
156
152
  def self.log
157
153
  @@logger
@@ -64,8 +64,8 @@ module Alexandria
64
64
  own || false
65
65
  end
66
66
 
67
- def ==(obj)
68
- obj.is_a?(self.class) && (ident == obj.ident)
67
+ def ==(other)
68
+ other.is_a?(self.class) && (ident == other.ident)
69
69
  end
70
70
 
71
71
  def inspect
@@ -17,6 +17,7 @@ module Alexandria
17
17
 
18
18
  attr_reader :name
19
19
  attr_accessor :ruined_books, :updating, :deleted_books
20
+
20
21
  DEFAULT_DIR = File.join(ENV["HOME"], ".alexandria")
21
22
  EXT = { book: ".yaml", cover: ".cover" }.freeze
22
23
 
@@ -95,8 +96,8 @@ module Alexandria
95
96
  end
96
97
 
97
98
  def self.ean_checksum(numbers)
98
- -(numbers.values_at(1, 3, 5, 7, 9, 11).reduce(:+) * 3 +
99
- numbers.values_at(0, 2, 4, 6, 8, 10).reduce(:+)) % 10
99
+ -(numbers.values_at(1, 3, 5, 7, 9, 11).sum * 3 +
100
+ numbers.values_at(0, 2, 4, 6, 8, 10).sum) % 10
100
101
  end
101
102
 
102
103
  def self.valid_ean?(ean)
@@ -108,8 +109,8 @@ module Alexandria
108
109
  end
109
110
 
110
111
  def self.upc_checksum(numbers)
111
- -(numbers.values_at(0, 2, 4, 6, 8, 10).reduce(:+) * 3 +
112
- numbers.values_at(1, 3, 5, 7, 9).reduce(:+)) % 10
112
+ -(numbers.values_at(0, 2, 4, 6, 8, 10).sum * 3 +
113
+ numbers.values_at(1, 3, 5, 7, 9).sum) % 10
113
114
  end
114
115
 
115
116
  def self.valid_upc?(upc)
@@ -221,11 +222,11 @@ module Alexandria
221
222
  File.open(yaml(temp_book), "w") { |io| io.puts temp_book.to_yaml }
222
223
 
223
224
  # Do not notify twice.
224
- if changed?
225
- notify_observers(self,
226
- already_there ? BOOK_UPDATED : BOOK_ADDED,
227
- book)
228
- end
225
+ return unless changed?
226
+
227
+ notify_observers(self,
228
+ already_there ? BOOK_UPDATED : BOOK_ADDED,
229
+ book)
229
230
  end
230
231
 
231
232
  def transport
@@ -283,7 +284,10 @@ module Alexandria
283
284
  else
284
285
  if @deleted_books.include?(book)
285
286
  doubles = @deleted_books.select { |b| b.equal?(book) }
286
- raise ArgumentError, "Book #{book.isbn} was already deleted" unless doubles.empty?
287
+ unless doubles.empty?
288
+ raise ArgumentError, format(_("Book %<isbn>s was already deleted"),
289
+ isbn: book.isbn)
290
+ end
287
291
  end
288
292
  @deleted_books << book
289
293
  i = index(book)
@@ -346,7 +350,7 @@ module Alexandria
346
350
  when Integer
347
351
  something
348
352
  else
349
- raise "#{something} is a #{something.class}"
353
+ raise NotImplementedError
350
354
  end
351
355
  File.join(path, ident.to_s + EXT[:cover])
352
356
  end
@@ -360,7 +364,7 @@ module Alexandria
360
364
  when Integer
361
365
  something
362
366
  else
363
- raise "#{something} is #{something.class}"
367
+ raise NotImplementedError
364
368
  end
365
369
  File.join(basedir, ident.to_s + EXT[:book])
366
370
  end
@@ -378,8 +382,8 @@ module Alexandria
378
382
  length - n_rated
379
383
  end
380
384
 
381
- def ==(object)
382
- object.is_a?(self.class) && object.name == name
385
+ def ==(other)
386
+ other.is_a?(self.class) && other.name == name
383
387
  end
384
388
 
385
389
  def copy_covers(somewhere)
@@ -38,10 +38,9 @@ module Alexandria
38
38
  @extra_request_headers.each_pair do |header_name, value|
39
39
  req.add_field(header_name, value)
40
40
  end
41
- res = WWWAgent.transport.start(uri.host, uri.port) do |http|
41
+ WWWAgent.transport.start(uri.host, uri.port) do |http|
42
42
  http.request(req)
43
43
  end
44
- res
45
44
  end
46
45
 
47
46
  def language=(lang)
@@ -57,30 +57,24 @@ module Alexandria
57
57
  @changed_settings.clear
58
58
  end
59
59
 
60
- def method_missing(id, *args)
61
- method = id.id2name
62
- if (match = /(.*)=$/.match(method))
63
- if args.length != 1
64
- raise "Set method #{method} should be called with " \
65
- "only one argument (was called with #{args.length})"
66
- end
67
- variable_name = match[1]
68
- new_value = args.first
69
- generic_setter(variable_name, new_value)
70
- else
71
- unless args.empty?
72
- raise "Get method #{method} should be called " \
73
- "without argument (was called with #{args.length})"
74
- end
75
- generic_getter(method)
76
- end
77
- end
78
-
79
60
  def remove_preference(variable_name)
80
61
  @alexandria_settings.delete(variable_name)
81
62
  @changed_settings << variable_name
82
63
  end
83
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
+
84
78
  private
85
79
 
86
80
  ##
@@ -140,11 +134,12 @@ module Alexandria
140
134
  ##
141
135
 
142
136
  def get_gconf_type(value)
143
- if value.is_a?(String)
137
+ case value
138
+ when String
144
139
  "string"
145
- elsif value.is_a?(Integer)
140
+ when Integer
146
141
  "int"
147
- elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
142
+ when TrueClass, FalseClass
148
143
  "bool"
149
144
  else
150
145
  "string"
@@ -168,24 +163,24 @@ module Alexandria
168
163
  end
169
164
 
170
165
  def make_list_string(list)
171
- list.map! { |x| x.gsub(/\"/, '\\"') } if get_gconf_type(list.first) == "string"
166
+ list.map! { |x| x.gsub(/"/, '\\"') } if get_gconf_type(list.first) == "string"
172
167
  contents = list.join(",")
173
168
  "[" + contents + "]"
174
169
  end
175
170
 
176
171
  def exec_gconf_set(var_path, new_value)
177
172
  if /cols_width/.match?(var_path)
178
- puts new_value
173
+ log.debug { new_value }
179
174
 
180
175
  # new_value = {}
181
176
  end
182
177
  type = get_gconf_type(new_value)
183
178
  value_str = new_value
184
179
  if new_value.is_a? String
185
- new_value = new_value.gsub(/\"/, '\\"')
180
+ new_value = new_value.gsub(/"/, '\\"')
186
181
  value_str = "\"#{new_value}\""
187
182
  end
188
- puts value_str if /cols_width/.match?(var_path)
183
+ log.debug { value_str } if /cols_width/.match?(var_path)
189
184
  `gconftool-2 --type #{type} --set #{var_path} #{value_str}`
190
185
  end
191
186
 
@@ -242,15 +237,16 @@ module Alexandria
242
237
  # gconftool. This is not fool-proof, but it *does* work for the
243
238
  # range of values used by Alexandria.
244
239
  def discriminate(value)
245
- if value == "true" # bool
240
+ case value
241
+ when "true" # bool
246
242
  true
247
- elsif value == "false" # bool
243
+ when "false" # bool
248
244
  false
249
- elsif /^[0-9]+$/.match?(value) # int
245
+ when /^[0-9]+$/ # int
250
246
  value.to_i
251
- elsif value =~ /^\[(.*)\]$/ # list (assume of type String)
247
+ when /^\[(.*)\]$/ # list (assume of type String)
252
248
  Regexp.last_match[1].split(",")
253
- elsif value =~ /^\((.*)\)$/ # pair (assume of type int)
249
+ when /^\((.*)\)$/ # pair (assume of type int)
254
250
  begin
255
251
  pair = Regexp.last_match[1].split(",")
256
252
  [discriminate(pair.first), discriminate(pair.last)]