Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created August 15, 2011 05:12
Show Gist options
  • Select an option

  • Save draftcode/1145741 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/1145741 to your computer and use it in GitHub Desktop.
#!/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