分析プロジェクトのために gedcom 5.5 ファイルを解析する必要があります。最初に見つけた ruby パーサーは、スタック レベルが深すぎるというエラーを引き起こしたので、別の方法を見つけようとしました。私はこのプロジェクトを見つけました: https://github.com/jslade/gedcom-ruby
いくつかのサンプルが含まれていますが、それらも機能しません。
パーサー自体は次のとおりです: https://github.com/jslade/gedcom-ruby/blob/master/lib/gedcom.rb
次のようにサンプルを試してみると:
ruby ./samples/count.rb ./samples/royal.ged
次のエラーが表示されます。
D:/rails_projects/gedom_test/lib/gedcom.rb:185:in `readchar': end of file reached (EOFError)
理解を深めるために、すべてのメソッドに「取得」を記述しました。これは、例外が発生するまでの出力です。
Parsing './samples/royal.ged'...
INIT
BEFORE
CHECK_PROC_OR_BLOCK
BEFORE
CHECK_PROC_OR_BLOCK
PARSE
PARSE_FILE
PARSE_IO
DETECT_RS
問題を引き起こす正確な行は
while ch = io.readchar
detect_rs メソッドで:
# valid gedcom may use either of \r or \r\n as the record separator.
# just in case, also detects simple \n as the separator as well
# detects the rs for this string by scanning ahead to the first occurence
# of either \r or \n, and checking the character after it
def detect_rs io
puts "DETECT_RS"
rs = "\x0d"
mark = io.pos
begin
while ch = io.readchar
case ch
when 0x0d
ch2 = io.readchar
if ch2 == 0x0a
rs = "\x0d\x0a"
end
break
when 0x0a
rs = "\x0a"
break
end
end
ensure
io.pos = mark
end
rs
end
誰かがこれで私を助けてくれることを願っています。