Class: YanSpeller::Speller

Inherits:
Object
  • Object
show all
Defined in:
lib/yan_speller/speller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpeller

Returns a new instance of Speller.



9
10
11
12
13
# File 'lib/yan_speller/speller.rb', line 9

def initialize
  @spell_request = SpellRequest.new
  @errors = []
  @status = :request_fail
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/yan_speller/speller.rb', line 7

def status
  @status
end

Instance Method Details

#check_spell(text) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yan_speller/speller.rb', line 15

def check_spell text
  result = @spell_request.send text
  if @spell_request.success?
    @errors = JSON.parse(result.body).map do |err|
      SpellError.new err
    end
    @status = @errors.empty? ? :no_spell_errors : :spell_errors
  else
    @status = :request_fail
  end
end

#errors_to_sObject



27
28
29
# File 'lib/yan_speller/speller.rb', line 27

def errors_to_s
  @errors.map { |err| err.to_s }
end