Class: Spellcard::Checker
- Inherits:
-
Object
- Object
- Spellcard::Checker
- Defined in:
- lib/spellcard/checker.rb
Instance Method Summary collapse
Instance Method Details
#find_typo(text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/spellcard/checker.rb', line 7 def find_typo(text) array = word_array(text) array.each.inject(Array.new) do |result, word| if is_english_word(word) == false result << word else result end end end |
#is_english_word(word) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/spellcard/checker.rb', line 22 def is_english_word(word) begin uri = 'http://public.dejizo.jp/NetDicV09.asmx/SearchDicItemLite?' + 'Dic=EJdict&Scope=HEADWORD&Merge=AND&Prof=XHTML&PageSize=20' + '&PageIndex=0&Match=EXACT&Word=' + word doc = Nokogiri::XML(open(uri).read) hash = Hash.from_xml(doc.to_s) count = hash["SearchDicItemResult"]["TotalHitCount"].to_i if count == 0 false else true end rescue true end end |
#word_array(text) ⇒ Object
18 19 20 |
# File 'lib/spellcard/checker.rb', line 18 def word_array(text) text.split(' ').map { |word| word.gsub(/,/, "").gsub(/\./, "") } end |