10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/petrarca/helpers.rb', line 10
def split(isbn)
isbn = Petrarca.dehyphenate(isbn)
ean_prefix = isbn[0, 3]
unless ean_prefix == "978" || ean_prefix == "979"
raise InvalidEANPrefixError.new("Invalid EAN prefix: #{ean_prefix}")
end
body = isbn[3, 9]
check_digit = isbn[12, 1]
begin
registration_group, body = Helpers.split_to_parts(body, REGISTRATION_GROUP_RANGES[ean_prefix])
rescue InvalidRangeError
raise InvalidRangeError.new("Registration group is not defined: #{body} (under #{ean_prefix})")
end
prefix = "#{ean_prefix}-#{registration_group}"
begin
registrant, publication = Helpers.split_to_parts(body, REGISTRANT_RANGES[prefix])
rescue InvalidRangeError
raise InvalidRangeError.new("Registrant is not defined: #{body} (under #{prefix})")
end
[ean_prefix, registration_group, registrant, publication, check_digit]
end
|