class Typingpool::Filer::Dir

Convenience wrapper for basic directory operations and for casting files to specific filer types (CSV, Audio).

Attributes

path[R]

Full expanded path to the dir

Public Class Methods

create(path) click to toggle source

Constructor. Takes full expanded path to the dir and creates the dir in the filesystem. Returns new Filer::Dir.

# File lib/typingpool/filer/dir.rb, line 21
def create(path)
  FileUtils.mkdir(path)
  new(path)
end
named(name, in_dir) click to toggle source

Constructor. Takes directory name and full expanded path of the parent directory. If the so-named directory exists within the parent directory, returns it. If not, returns nil.

# File lib/typingpool/filer/dir.rb, line 29
def named(name, in_dir)
  path = File.join(in_dir, name)
  if File.exist?(path) && File.directory?(path)
    new(path)
  end
end
new(path) click to toggle source

Constructor. Takes full expanded path to the dir. Does NOT create dir in the filesystem.

# File lib/typingpool/filer/dir.rb, line 13
def initialize(path)
  @path = path
end

Public Instance Methods

file(*relative_path) click to toggle source

Takes an aribtrary number of path elements relative to the Filer::Dir instance. So a file in the subdir path/to/file.txt would be referenced via file('path', 'to', 'file.txt'). Returns a new Filer instance wrapping the referenced file. Does not guarantee that the referenced file exists.

# File lib/typingpool/filer/dir.rb, line 48
def file(*relative_path)
  Filer.new(file_path(*relative_path))
end
file_path(*relative_path) click to toggle source
# File lib/typingpool/filer/dir.rb, line 70
def file_path(*relative_path)
  File.join(@path, *relative_path)
end
files() click to toggle source

Returns the files in the Filer::Dir directory as Filer instances. Excludes files whose names start with a dot.

# File lib/typingpool/filer/dir.rb, line 54
def files
  ::Dir.entries(@path).select{|entry| File.file? file_path(entry) }.reject{|entry| entry.match(/^\./) }.map{|entry| self.file(entry) }
end
finder_open() click to toggle source

OS X specific. Opens the dir in the Finder via the 'open' command.

# File lib/typingpool/filer/dir.rb, line 66
def finder_open
  system('open', @path)
end
subdir(*relative_path) click to toggle source

Takes relative path elements as params just like the file method. Returns a new Filer::Dir instance wrapping the referenced subdir.

# File lib/typingpool/filer/dir.rb, line 61
def subdir(*relative_path)
  Dir.new(file_path(*relative_path))
end
to_s() click to toggle source

Filer::Dir isntances stringify to their path.

# File lib/typingpool/filer/dir.rb, line 38
def to_s
  @path
end
Also aliased as: to_str
to_str()
Alias for: to_s