Created
August 15, 2011 05:12
-
-
Save draftcode/1145741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| # ISBN13のコードをISBN10に変換して読書メーターのページを開くスクリプト | |
| def isbn13_to_isbn10(s) | |
| i = 10 | |
| sum = 0 | |
| s[3..-2].split(//).each do |c| | |
| sum += c.to_i * i | |
| i -= 1 | |
| end | |
| if sum % 11 == 0 then | |
| s[3..-2] + "0" | |
| elsif sum % 11 == 1 then | |
| s[3..-2] + "X" | |
| else | |
| s[3..-2] + (11 - (sum % 11)).to_s | |
| end | |
| end | |
| while line = STDIN.gets | |
| system "open http://book.akahoshitakuya.com/b/" + isbn13_to_isbn10(line.chomp) | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment