Class: RftpDirectory

Inherits:
RftpFile show all
Defined in:
lib/rftp.rb

Instance Attribute Summary collapse

Attributes inherited from RftpFile

#group, #last_modified, #name, #owner, #parent, #path, #permissions, #size

Instance Method Summary collapse

Methods inherited from RftpFile

#connection, #parse_parts

Constructor Details

#initialize(path, parent, lines = nil, parts = nil) ⇒ RftpDirectory

Returns a new instance of RftpDirectory.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rftp.rb', line 66

def initialize(path, parent, lines = nil, parts = nil)
  self.parent = parent
  self.path = path
  if lines
    self.files = []
    lines.each do |line|
      parts = line.split(/\s+/) 
      
      if parts[0] =~ /^d/
        self.files << RftpDirectory.new("#{self.path}#{parts.last}/", self, nil, parts)
      else
        self.files << RftpFile.new(parts, self)
      end
    end

  else
    parse_parts(parts)
  end
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

Instance Method Details

#[](num) ⇒ Object



106
107
108
# File 'lib/rftp.rb', line 106

def [](num)
  ls[num]
end

#collect(&block) ⇒ Object



100
101
102
103
104
# File 'lib/rftp.rb', line 100

def collect(&block)
  ls.collect do |file|
    yield file
  end
end

#contentsObject



62
63
64
# File 'lib/rftp.rb', line 62

def contents
  raise "Can't get contents of a directory, use ls"
end

#dir?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rftp.rb', line 58

def dir?
  true
end

#each(&block) ⇒ Object



94
95
96
97
98
# File 'lib/rftp.rb', line 94

def each(&block)
  ls.each do |file|
    yield file
  end
end

#file?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rftp.rb', line 54

def file?
  false
end

#lsObject



86
87
88
89
90
91
92
# File 'lib/rftp.rb', line 86

def ls
  if self.files
    self.files
  else
    parent.ls(path)
  end
end