Class: Gtiny::ISBN
Overview
It seems like GTINs can also be encoded as ISBNs, which are either 10 or 13 digits.
ISBN-13s always have a 978 or 979 prefix, though that may be expanded in the future.
Prior to ISBNs, “SBNs” were used and were either 9 or 12 digits. A 9 digit SBN can be converted to an ISBN by prefixing it with a single zero. A 12 digit SBN can be converted to a 9 digit SBN by dropping the last three digits, which were often the price of the book.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Encoding
#initialize, matches?, regex, #to_s, #type, #zeroes?
Class Method Details
.normalize(string) ⇒ Object
17
18
19
|
# File 'lib/gtiny/isbn.rb', line 17
def self.normalize(string)
string.downcase.gsub(" ", "-")
end
|
Instance Method Details
#check_digit ⇒ Object
21
22
23
|
# File 'lib/gtiny/isbn.rb', line 21
def check_digit
string[-1]
end
|
#group_identifier ⇒ Object
25
26
27
28
29
|
# File 'lib/gtiny/isbn.rb', line 25
def group_identifier
check_number_of_groups!
groups[-4]
end
|
#publisher_identifier ⇒ Object
31
32
33
34
35
|
# File 'lib/gtiny/isbn.rb', line 31
def publisher_identifier
check_number_of_groups!
groups[-3]
end
|
#title_identifier ⇒ Object
37
38
39
40
41
|
# File 'lib/gtiny/isbn.rb', line 37
def title_identifier
check_number_of_groups!
groups[-2]
end
|
#valid? ⇒ Boolean
43
44
45
46
47
|
# File 'lib/gtiny/isbn.rb', line 43
def valid?
self.class.regex.match?(string) &&
digits.size == canonical_digits_size &&
valid_check_digit?
end
|