Module: DirectoryLoader
- Defined in:
- lib/asker/loader/directory_loader.rb
Class Method Summary collapse
-
.call(dirname) ⇒ Object
Load input data from one directory.
- .check_dir(dirname) ⇒ Object
-
.load_files(filenames, dirname) ⇒ Object
Load files from dirname directory.
Class Method Details
.call(dirname) ⇒ Object
Load input data from one directory
10 11 12 13 14 15 16 |
# File 'lib/asker/loader/directory_loader.rb', line 10 def self.call(dirname) DirectoryLoader.check_dir(dirname) files = (Dir.new(dirname).entries - [".", ".."]).sort # Accept only HAML or XML files accepted = files.select { |f| %w[.xml .haml].include? File.extname(f) } DirectoryLoader.load_files(accepted, dirname) end |
.check_dir(dirname) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/asker/loader/directory_loader.rb', line 18 def self.check_dir(dirname) return if Dir.exist? dirname Logger.error "DirectoryLoader: #{dirname} directory dosn't exist!" exit 1 end |
.load_files(filenames, dirname) ⇒ Object
Load files from dirname directory
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asker/loader/directory_loader.rb', line 29 def self.load_files(filenames, dirname) data = {concepts: [], codes: [], problems: []} filenames.each do |filename| filepath = File.join(dirname, filename) loaded = FileLoader.call(filepath) data[:concepts] += loaded[:concepts] data[:codes] += loaded[:codes] data[:problems] += loaded[:problems] end data end |