Class: FTPUtils::FTPURI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dirname, filename, path) ⇒ FTPURI



19
20
21
22
23
# File 'lib/ftputils/ftpuri.rb', line 19

def initialize(dirname, filename, path)
  self.dirname = dirname
  self.filename = filename
  self.path = path
end

Instance Attribute Details

#dirnameObject

Returns the value of attribute dirname.



3
4
5
# File 'lib/ftputils/ftpuri.rb', line 3

def dirname
  @dirname
end

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'lib/ftputils/ftpuri.rb', line 3

def filename
  @filename
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/ftputils/ftpuri.rb', line 3

def path
  @path
end

Class Method Details

.parse(uri) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ftputils/ftpuri.rb', line 5

def self.parse(uri)
  if uri.match(/^ftp:\/\/.*?:.*?@.*?(\/.*)*$/)
    path = $1 || "/"
    parts = path.split(/\//)
    filename = parts[-1]
    dirname = parts[0..-2].join("\/")
    dirname = "/" if dirname.empty?

    ftp_uri = FTPURI.new(dirname, filename, path)
  else
    return nil
  end
end