8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rag_ruby/loaders/file.rb', line 8
def load(path)
path = ::File.expand_path(path)
raise ArgumentError, "File not found: #{path}" unless ::File.exist?(path)
ext = ::File.extname(path).downcase
unless SUPPORTED_EXTENSIONS.include?(ext)
raise ArgumentError, "Unsupported file type: #{ext}. Supported: #{SUPPORTED_EXTENSIONS.join(', ')}"
end
content = ::File.read(path, encoding: "UTF-8")
[Document.new(
content: content,
metadata: {
source: path,
filename: ::File.basename(path),
extension: ext,
size: ::File.size(path)
},
source: path
)]
end
|