Class: MultiFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/file_obj.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ MultiFiles

Returns a new instance of MultiFiles.



42
43
44
# File 'lib/file_obj.rb', line 42

def initialize(paths)
  @paths = paths
end

Instance Attribute Details

#pathsObject

an array of file paths



40
41
42
# File 'lib/file_obj.rb', line 40

def paths
  @paths
end

Instance Method Details

#dirObject

all directories

For a list of all unique directories, use ‘$files.dir.uniq`



66
67
68
# File 'lib/file_obj.rb', line 66

def dir
  @paths.map { |p| File.dirname(p) }
end

#each(&f) ⇒ Object

loop over each file



71
72
73
74
75
# File 'lib/file_obj.rb', line 71

def each(&f)
  @paths.each do |p|
    f.call(p)
  end
end

#extsObject

all file extensions

For a list of all unique extensions, use ‘$files.exts.uniq`



59
60
61
# File 'lib/file_obj.rb', line 59

def exts
  @paths.map { |p| File.extname(p) }
end

#full_namesObject

all file names, including their extensions



52
53
54
# File 'lib/file_obj.rb', line 52

def full_names
  @paths.map { |p| File.basename(p) }
end

#namesObject

an array of all file names, without extensions



47
48
49
# File 'lib/file_obj.rb', line 47

def names
  @paths.map { |p| File.basename(p, ".*") }
end

#to_sObject

will return a space separated list of files, surrounded with quotes



78
79
80
# File 'lib/file_obj.rb', line 78

def to_s
  @paths.inject("") { |list, elem| list + " \"#{elem}\"" }.strip
end