class Forspell::Loaders::Base

Public Class Methods

new(file: nil, text: nil) click to toggle source
# File lib/forspell/loaders/base.rb, line 12
def initialize(file: nil, text: nil)
  @file = file
  @input = text || input
  @words = []
  @errors = []
end

Public Instance Methods

read() click to toggle source
# File lib/forspell/loaders/base.rb, line 19
def read
  extract_words.each { |word| word.text = Forspell::Sanitizer.sanitize(word.text) }
               .select{ |word| Forspell::WordMatcher.word?(word.text) }
               .reject { |w| w.text.nil? || w.text.empty? }
rescue YARD::Parser::ParserSyntaxError, RuntimeError => e
  raise Forspell::Loaders::ParsingError, e.message
end

Private Instance Methods

extract_words() click to toggle source
# File lib/forspell/loaders/base.rb, line 33
def extract_words
  raise NotImplementedError
end
input() click to toggle source
# File lib/forspell/loaders/base.rb, line 29
def input
  File.read(@file)
end