Module: BookToolkit
- Defined in:
- lib/book_toolkit/api_parser/campus_books.rb,
lib/book_toolkit.rb,
lib/book_toolkit/version.rb,
lib/book_toolkit/book_data.rb,
lib/book_toolkit/api_parser.rb,
lib/book_toolkit/api_parser/open_library.rb
Overview
{
"ISBN:9780387290959": {
"bib_key": "ISBN:9780387290959",
"preview": "restricted",
"preview_url": "https://archive.org/details/algebraiccombina2003liye",
"info_url": "http://openlibrary.org/books/OL22723183M/Orthogonal_frequency_division_mutiplexing_for_wireless_communications",
"details": {
"publishers": [
"Springer"
],
"pagination": "xii, 306 p. :",
"identifiers": {
"librarything": [
"6252855"
],
"goodreads": [
"1539554"
]
},
"lc_classifications": [
"TK"
],
"source_records": [
"ia:algebraiccombina2003liye"
],
"title": "Orthogonal frequency division mutiplexing for wireless communications",
"type": {
"key": "/type/edition"
},
"number_of_pages": 306,
"created": {
"type": "/type/datetime",
"value": "2008-12-19T12:48:38.432497"
},
"languages": [
{
"key": "/languages/eng"
}
],
"isbn_10": [
"0387290958"
],
"latest_revision": 4,
"publish_country": "us ",
"key": "/books/OL22723183M",
"last_modified": {
"type": "/type/datetime",
"value": "2014-07-28T10:19:56.239872"
},
"publish_date": "2004",
"publish_places": [
"New York, NY"
],
"works": [
{
"key": "/works/OL16920397W"
}
],
"ocaid": "algebraiccombina2003liye",
"by_statement": "edited by Ye (Geoffrey) Li, Gordon Stüber.",
"revision": 4
}
}
}
Defined Under Namespace
Modules: ApiParser Classes: BookData
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.calculate_checksum(isbn) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/book_toolkit.rb', line 25 def calculate_checksum(isbn) isbn.gsub!(/[^(\d|X)]/, '') c = 0 if isbn.length <= 10 10.downto(2) {|i| c += isbn[10-i].to_i * i} c %= 11 c = 11 - c c ='X' if c == 10 return c elsif isbn.length <= 13 (1..11).step(2) {|i| c += isbn[i].to_i} c *= 3 (0..11).step(2) {|i| c += isbn[i].to_i} c = (220-c) % 10 return c end end |
.to_isbn13(isbn) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/book_toolkit.rb', line 12 def to_isbn13 isbn case isbn.length when 13 return ISBN.thirteen isbn when 10 return ISBN.thirteen isbn when 12 return "#{isbn}#{BookToolkit.calculate_checksum(isbn)}" when 9 return ISBN.thirteen("#{isbn}#{BookToolkit.calculate_checksum(isbn)}") end end |