Class: Forspell::Loaders::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/forspell/loaders/base.rb

Direct Known Subclasses

Markdown, Source

Instance Method Summary collapse

Constructor Details

#initialize(file: nil, text: nil) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/forspell/loaders/base.rb', line 12

def initialize(file: nil, text: nil)
  @file = file
  @input = text || input
  @words = []
  @errors = []
end

Instance Method Details

#readObject



19
20
21
22
23
24
25
# 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