Class: MultiFiles
- Inherits:
-
Object
- Object
- MultiFiles
- Defined in:
- lib/file_obj.rb
Instance Attribute Summary collapse
-
#paths ⇒ Object
an array of file paths.
Instance Method Summary collapse
-
#dir ⇒ Object
all directories.
-
#each(&f) ⇒ Object
loop over each file.
-
#exts ⇒ Object
all file extensions.
-
#full_names ⇒ Object
all file names, including their extensions.
-
#initialize(paths) ⇒ MultiFiles
constructor
A new instance of MultiFiles.
-
#names ⇒ Object
an array of all file names, without extensions.
-
#to_s ⇒ Object
will return a space separated list of files, surrounded with quotes.
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
#paths ⇒ Object
an array of file paths
40 41 42 |
# File 'lib/file_obj.rb', line 40 def paths @paths end |
Instance Method Details
#dir ⇒ Object
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 |
#exts ⇒ Object
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_names ⇒ Object
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 |
#names ⇒ Object
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_s ⇒ Object
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 |