Sha256: ae4153351bb656a089f9866e79d157cf34d00cb95084c7194db73ca9151ef05e
Contents?: true
Size: 1.59 KB
Versions: 6
Compression:
Stored size: 1.59 KB
Contents
# frozen_string_literal: true # Alfonso X module module AlfonsoX module SpellChecker # Each of the spell-checked words class Word attr_reader :word, :line # Initialize a spell-checked word. # @param [String] word Word to be spell-checked. # @param [Integer] line Line number this word belongs to. # @param [Array<AlfonsoX::SpellChecker::Dictionary::Hunspell, AlfonsoX::SpellChecker::Dictionary::Rubymine>] # dictionaries Array of dictionaries that will be used to check if this word spelling is right. def initialize(word, line, dictionaries) @word = word @line = line @dictionaries = dictionaries @right = nil end # Check if the word is right. # Assigns the Word#right attribute. # @return [Boolean] true if the word is rightfully written, false otherwise. def check @dictionaries.each do |dictionary| @right = check_for_dictionary(dictionary) return true if @right end false end private # Check if the word is rightfully written for a dictionary. # @param [Array<AlfonsoX::SpellChecker::Dictionary::Hunspell, AlfonsoX::SpellChecker::Dictionary::Rubymine>] # dictionaries Array of dictionaries that will be used to check if this word spelling is right. # @return [Boolean] true if the word is rightfully written for the passed dictionary, false otherwise. def check_for_dictionary(dictionary) right = dictionary.word_present?(@word) return true if right false end end end end
Version data entries
6 entries across 6 versions & 1 rubygems