class FC

Constants

VERSION

Attributes

files[R]
path[R]

Public Class Methods

new(dir_path, files: []) click to toggle source
# File lib/fc.rb, line 35
def initialize(dir_path, files: [])
  raise Error::DirectoryDoesNotExist unless ::File.directory?(dir_path)

  @path = dir_path
  @files = files
end

Public Instance Methods

filter(recursive: false) { |file| ... } click to toggle source
# File lib/fc.rb, line 42
def filter(recursive: false)
  clear
  return self unless block_given?

  index(recursive: recursive) { |file| @files << file if yield(file) }
  self
end
index(recursive: false, &block) click to toggle source
# File lib/fc.rb, line 50
def index(recursive: false, &block)
  indexed_files = []
  Dir.each_child(path) do |filename|
    filepath = ::File.join(path, filename)
    if ::File.file?(filepath)
      tmp = FC::File.new(filepath)
      indexed_files << tmp
      block.call(tmp)
    elsif recursive
      tmp_array = FC
        .new(filepath)
        .index(recursive: recursive, &block)
      indexed_files.concat(tmp_array)
    end
  end
  indexed_files
end