Module: SimpleSpeller

Defined in:
lib/simple_speller.rb,
lib/simple_speller/version.rb

Constant Summary collapse

SERVICE_URL =
'https://speller.yandex.net/services/spellservice.json/checkText?text='.freeze
VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.check(text, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/simple_speller.rb', line 8

def self.check(text, options = {})
  response = HTTParty.post(SERVICE_URL + CGI.escape(text),
                           body:    { lang:    options[:lang] || 'ru,en',
                                      format:  'pain',
                                      options: 518 }.to_json,
                           headers: { 'Content-Type' => 'application/json' })
  JSON.parse response.body
end

.fix(text, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/simple_speller.rb', line 17

def self.fix(text, options = {})
  t = text.dup
  check(text, options).each do |ehash|
    start_i           = ehash['pos']
    end_i             = start_i + ehash['len'] - 1
    t[start_i..end_i] = ehash['s'].first
  end
  t
end