Class: SycLink::FileImporter

Inherits:
Importer show all
Defined in:
lib/syclink/file_importer.rb

Constant Summary

Constants inherited from Importer

Importer::CLEANER

Instance Attribute Summary

Attributes inherited from Importer

#opts, #path

Instance Method Summary collapse

Methods inherited from Importer

#initialize, #links, #rows

Constructor Details

This class inherits a constructor from SycLink::Importer

Instance Method Details

#readObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/syclink/file_importer.rb', line 5

def read
  root_dir = File.dirname(path).scan(/^[^\*|\?]*/).first
  regex = Regexp.new("(?<=#{root_dir}).*")
  Dir.glob(path).map do |file|
    next if File.directory? file
    url, name = if File.extname(file).upcase == ".URL"
                  begin
                    [File.read(file).scan(/(?<=\nURL=)(.*)$/)
                                    .flatten.first.chomp,
                     url_name(File.basename(file, ".*"))]
                  rescue
                    [file, File.basename(file)]
                  end
                else
                  [file, File.basename(file)]
                end
    description = ""
    tags = extract_tags(File.dirname(file).scan(regex))
    [url, name, description, tags]
  end.compact
end