Module: Petrarca
- Extended by:
- Petrarca
- Included in:
- Petrarca
- Defined in:
- lib/petrarca.rb,
lib/petrarca/isbn10.rb,
lib/petrarca/isbn13.rb,
lib/petrarca/helpers.rb,
lib/petrarca/version.rb
Defined Under Namespace
Modules: Helpers, ISBN10, ISBN13
Classes: Error, IncorrectFormatError, InvalidEANPrefixError, InvalidRangeError
Constant Summary
collapse
- REGISTRATION_GROUP_RANGES =
Helpers.load_ranges("#{data_dir}/registration_group_ranges.txt")
- REGISTRANT_RANGES =
Helpers.load_ranges("#{data_dir}/registrant_ranges.txt")
- VERSION =
"0.6.6"
Instance Method Summary
collapse
Instance Method Details
#calc_check_digit(isbn) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/petrarca.rb', line 28
def correct_format?(isbn)
case dehyphenate(isbn).size
when 13
ISBN13.correct_format?(isbn)
when 10
ISBN10.correct_format?(isbn)
else
false
end
end
|
#dehyphenate(isbn) ⇒ Object
51
52
53
|
# File 'lib/petrarca.rb', line 51
def dehyphenate(isbn)
isbn.to_s.delete("-")
end
|
#hyphenate(isbn) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/petrarca.rb', line 55
def hyphenate(isbn)
isbn = isbn.to_s
case isbn.size
when 13
ISBN13.hyphenate(isbn)
when 10
ISBN10.hyphenate(isbn)
end
end
|
#split(isbn) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/petrarca.rb', line 65
def split(isbn)
isbn = isbn.to_s
case isbn.size
when 13
ISBN13.split(isbn)
when 10
ISBN10.split(isbn)
end
end
|
#valid?(isbn) ⇒ Boolean
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/petrarca.rb', line 17
def valid?(isbn)
case dehyphenate(isbn).size
when 13
ISBN13.valid?(isbn)
when 10
ISBN10.valid?(isbn)
else
false
end
end
|