class GrammarNazi
Constants
- URL
Attributes
errors[R]
Public Class Methods
new(client: HTTPClient.new, lang: "
click to toggle source
# File lib/grammar_nazi.rb, line 10 def initialize client: HTTPClient.new, lang: "#{:ru}, #{:en}" @client = client @lang = lang @errors = [] end
Public Instance Methods
check(text)
click to toggle source
# File lib/grammar_nazi.rb, line 16 def check text @text = text @errors.clear @errors = JSON.parse @client.get(URL, { text: text, lang: @lang }) end
result()
click to toggle source
# File lib/grammar_nazi.rb, line 22 def result puts 'Текст:' puts @text puts 'Результат проверки:' if @errors.any? @errors.each { |error| print_error error } else puts 'Ошибок не найдено.' end end
Private Instance Methods
print_error(error)
click to toggle source
# File lib/grammar_nazi.rb, line 36 def print_error error locate = "(строка: #{error['row']}, позиция #{error['pos']})" if error['s'].any? puts "#{error['word']} -> #{error['s'].join(', ')} #{locate}" else puts "#{error['word']} -> ??? #{locate}" end end