Class: Phronomy::Loader::PlainTextLoader

Inherits:
Base
  • Object
show all
Defined in:
lib/phronomy/loader/plain_text_loader.rb

Overview

Loads a plain-text file as a single document.

Examples:

loader = Phronomy::Loader::PlainTextLoader.new
docs   = loader.load("/path/to/file.txt")
# => [{ text: "...", metadata: { source: "/path/to/file.txt" } }]

Instance Method Summary collapse

Instance Method Details

#load(source) ⇒ Array<Hash>

Returns single-element array with the file contents.

Parameters:

  • source (String)

    absolute or relative path to a text file

Returns:

  • (Array<Hash>)

    single-element array with the file contents

Raises:

  • (Errno::ENOENT)

    if the file does not exist



15
16
17
18
# File 'lib/phronomy/loader/plain_text_loader.rb', line 15

def load(source)
  text = File.read(source, encoding: "UTF-8")
  [{text: text, metadata: {source: source}}]
end