# $Id: bookstore.rb,v 1.6 2001/06/21 22:47:30 not Exp $
=begin
usage:
(ISBN4-04-873259-5) とか書いとくと各オンライン書店へのリンクに変換
アソシエイト・プログラムに参加している場合は ndiary.conf に以下の行を追加
もちろん自分の ID に直して。
# bk1
BOOKSTORE_BK1_ID = 'p-not00114'
# amazon
BOOKSTORE_AMAZON_ID = 'notsfragmen-22'
松下さん(http://www.alles.or.jp/~akihisa/)のオンライン書店へのリンクを
参考に作成。
その後、細井さん(http://www.fan.gr.jp/~hosoi/diary/diary.html)による洋書
のリンクを追加。
=end
class Filter
# BOOKSTORE = Regexp::compile(/[\((]ISBN(\d-[\d-]{9}-\w)[\))]/)
BOOKSTORE = Regexp::compile(/[\((]ISBN[:|:]?\s?(\d-[\d-]{9}[-]?[\w]?)[\))]/)
AMAZONIMAGE = Regexp::compile(/[\((]IMAGE[:|:]?\s?(\d-[\d-]{9}[-]?[\w]?)[\))]/)
AMAZONIMAGE2 = Regexp::compile(/[\((]IMAGE2[:|:]?\s?(\d-[\d-]{9}[-]?[\w]?)[\))]/)
TITLE = Regexp::compile(/[\((]TITLE[:|:|\s]?(.+)[\))]/)
def bookstore_y(str, type)
bk1_id = @diary.config['BOOKSTORE_BK1_ID'].to_s
amazon_id = @diary.config['BOOKSTORE_AMAZON_ID'].to_s
bk1_id = 'aid=' + bk1_id + '&' unless bk1_id.empty?
case type
when :P, :UL, :DL
str.gsub!(BOOKSTORE){
$stderr.puts "CHK; bookstore; " << $1
isbn = $1
# check_isbn(isbn)
isbn2 = isbn.delete('-')
t = '
'
t << ''
t << '
'
t << ''
if isbn2 =~ /^4/
t << '【 '
t << 'bk1 / '
t << 'amazon / '
t << 'ISIZE / '
t << '旭屋 / '
t << 'Jbook / '
t << 'BOL / '
t << '紀伊國屋 / '
t << 'eS! / '
t << '楽天 / '
t << '富士山 / '
t << '本屋さん 】'
elsif isbn2 =~ /^0/
t << '【 '
t << 'amazon.co.jp / '
t << 'skysoft / '
t << 'amazon.com / '
t << 'Barnes & Noble / '
t << 'A1Books / '
t << 'Powells.com / '
t << 'Borders / '
t << '紀伊國屋 / '
t << '丸善 】'
elsif isbn2~ /^1/
t << '【 '
t << 'amazon.co.uk / '
t << 'The Internet Bookshop / '
t << 'bol 】'
end
# t << '
'
t << '
'
}
end
end
def check_isbn(isbn)
isbn2 = isbn.delete('-')
t = ''
check = 1
check = 11 - ((((isbn2[0] - 48) * 10) + ((isbn2[1] - 48) * 9) + ((isbn2[2] - 48) * 8) + ((isbn2[3] - 48) * 7) + ((isbn2[4] - 48) * 6) + ((isbn2[5] - 48) * 5) + ((isbn2[6] - 48) * 4) + ((isbn2[7] - 48) * 3) + ((isbn2[8] - 48) * 2)) % 11)
# check = 11 - (( (isbn2[0] * 10) + (isbn2[1] * 9) + (isbn2[2] * 8) + (isbn2[3] * 7) + (isbn2[4] * 6) + (isbn2[5] * 5) + (isbn2[6] * 4) + (isbn2[7] * 3) + (isbn2[8] * 2)) % 11)
digit = check.to_s
digit = 'X' if check == 10
digit = '0' if check == 11
if isbn2.size < 10 then
$stderr.puts "Warning: ISBN check-digit lost. -> #{digit}"
test = (isbn2[0]).to_s
isbn2 = isbn2 + digit
if isbn =~ /-$/ then
isbn = isbn + digit
else
isbn = isbn + "-" + digit
end
else
check = (isbn2[9] - 48).to_s
check = 'X' if (isbn2[9] == 'X') || (isbn2[9] == 'x')
if (check !~ digit) && ( check != '40') then
$stderr.puts "Warning: ISBN check-digit error. #{check} -> #{digit}"
t << "Warning ISBN check-digit error\n"
isbn2[9] = digit
isbn.gsub!(/-.$/,"-#{digit}")
end
end
end
end