lib/alexandria/models/library.rb in alexandria-book-collection-manager-0.7.0 vs lib/alexandria/models/library.rb in alexandria-book-collection-manager-0.7.1
- old
+ new
@@ -23,16 +23,10 @@
require 'etc'
require 'open-uri'
require 'observer'
require 'singleton'
-class Array
- def sum
- reduce(0) { |a, b| a + b }
- end
-end
-
module Alexandria
class Library < Array
include Logging
attr_reader :name
@@ -268,13 +262,10 @@
dest_library.notify_observers(dest_library, BOOK_ADDED, book)
end
end
class NoISBNError < StandardError
- def initialize(msg)
- super(msg)
- end
end
class InvalidISBNError < StandardError
attr_reader :isbn
def initialize(isbn = nil)
@@ -306,12 +297,12 @@
rescue InvalidISBNError
false
end
def self.ean_checksum(numbers)
- (10 - ([1, 3, 5, 7, 9, 11].map { |x| numbers[x] }.sum * 3 +
- [0, 2, 4, 6, 8, 10].map { |x| numbers[x] }.sum)) % 10
+ -(numbers.values_at(1, 3, 5, 7, 9, 11).reduce(:+) * 3 +
+ numbers.values_at(0, 2, 4, 6, 8, 10).reduce(:+)) % 10
end
def self.valid_ean?(ean)
numbers = extract_numbers(ean)
((numbers.length == 13) &&
@@ -321,12 +312,12 @@
rescue InvalidISBNError
false
end
def self.upc_checksum(numbers)
- (10 - ([0, 2, 4, 6, 8, 10].map { |x| numbers[x] }.sum * 3 +
- [1, 3, 5, 7, 9].map { |x| numbers[x] }.sum)) % 10
+ -(numbers.values_at(0, 2, 4, 6, 8, 10).reduce(:+) * 3 +
+ numbers.values_at(1, 3, 5, 7, 9).reduce(:+)) % 10
end
def self.valid_upc?(upc)
numbers = extract_numbers(upc)
((numbers.length == 17) &&
@@ -569,12 +560,10 @@
end
when String
something
when Integer
something
- when Integer
- something
else
raise "#{something} is a #{something.class}"
end
File.join(path, ident.to_s + EXT[:cover])
end
@@ -582,11 +571,9 @@
def yaml(something, basedir = path)
ident = case something
when Book
something.ident
when String
- something
- when Integer
something
when Integer
something
else
raise "#{something} is #{something.class}"