速報:scRUBYt! で漢字を通す

EUC-JP とか Shift_JIS とかのソースを scRUBYt! にそのまま通すと氏ぬっぽいのでがんがってみた。
ぐぐっても資料が見付からなかったので資料第一号を名乗ってみるテスト。
まずは /scrubyt-0.2.6 でこのパッチを当てる。

--- lib/scrubyt/core/navigation/navigation_actions.rb.orig      2007-04-06 15:27:32.000000000 +0900
+++ lib/scrubyt/core/navigation/navigation_actions.rb   2007-04-06 15:27:43.000000000 +0900
@@ -54,7 +54,7 @@
     ##
     #Fetch the document
     def self.fetch(doc_url, mechanize_doc=nil)
-      FetchAction.fetch(doc_url, mechanize_doc)
+      FetchAction.fetch(doc_url, nil, mechanize_doc)
     end
     ##
     #Submit the current form (delegate it to NavigationActions)

そして Learning パーサを、たとえば産経の News Flash なら次のように書く。

#!/usr/bin/ruby -Ke

$KCODE = 'e'

require 'kconv'
require 'rubygems'
require 'scrubyt'
require 'nkf'

NEWSFLASH = "http://www.sankei.co.jp/flash/flash.htm"

sankei = Scrubyt::Extractor.define do
  mechanize = WWW::Mechanize.new
  mechanize_doc = mechanize.get(NEWSFLASH)

  # UTF-8 にすれば扱えるみたいだ
  mechanize_doc.body = NKF.nkf('--utf8', mechanize_doc.body)

  # navigate_actions.rb にパッチを当てないと、ここで引数不一致になる
  fetch(NEWSFLASH, mechanize_doc)

  # 試すときは,最新の記事に差し替えて
  record do
    title "カーコリアン氏が買収提案".toutf8
    time '13:24'
    abstract ("経営不振のクライスラーを45億ドルで。" +
              "ダイムラーが交渉を進めていることを認めた。").toutf8
  end.ensure_presence_of_pattern('abstract')

end

sankei.to_xml.write($stdout, 1)

Scrubyt::ResultDumper.print_statistics(sankei)

Production パーサはこれから作ってみる。