2013-09-24 39 views
0

我正在嘗試使用gem charlock_holmes(https://github.com/brianmario/charlock_holmes)來檢測和更正字符格式錯誤。但是,該程序不會返回任何內容。Charlock_Holmes不會在Ruby中返回任何內容?

我的代碼是:

require 'charlock_holmes' 
contents = File.read('./myfile.csv') 
detection = CharlockHolmes::EncodingDetector.detect(contents) 
# => {:encoding => 'UTF-8', :confidence => 100, :type => :text} 

,如文檔中指定。

當我在目錄中運行這個,我只是什麼都得不到:

user$ ruby detector.rb 
user$ 

預期的行爲是它返回檢測到編碼(如果需要的話,可以改變它)。我想,我已經安裝了所有的寶石,並且我已經在1.9.2和2.0.0下試過了。

任何想法我做錯了什麼或如何找出?恐怕我對ruby並不陌生,但我曾試圖在提問之前進行一次非常全面的搜索,並且已經空白。

回答

1

我想你應該把p detection放在你的文件detector.rb

保存你的代碼如下:

require 'charlock_holmes' 
contents = File.read('./myfile.csv') 
detection = CharlockHolmes::EncodingDetector.detect(contents) 
p detection 

現在運行它,你前面跑去。

+0

工作正常!謝謝! – peteyreplies

相關問題