Class: Net::FTP::List::Entry
- Inherits:
-
Object
- Object
- Net::FTP::List::Entry
- Includes:
- Comparable
- Defined in:
- lib/net/ftp/list/entry.rb
Overview
Represents an entry of the FTP list. Gets returned when you parse a list.
Constant Summary
- ALLOWED_ATTRIBUTES =
:nodoc:
[:raw, :basename, :dir, :file, :symlink, :mtime, :filesize, :device, :server_type]
Instance Method Summary (collapse)
-
- (Fixnum) <=>(other)
Compares the receiver against another object.
-
- (Object) basename
(also: #name)
The items basename (filename).
-
- (Boolean) device?
Looks like a device.
-
- (Boolean) dir?
(also: #directory?)
Looks like a directory, try CWD.
-
- (true, false) eql?(other)
Tests for objects equality (value and type).
-
- (Boolean) file?
Looks like a file, try RETR.
-
- (Object) filesize
(also: #size)
Returns the filesize of the entry or 0 for directorties.
-
- (Entry) initialize(raw_ls_line, optional_attributes = {})
constructor
Create a new entry object.
-
- (Object) mtime
Returns the modification time of the file/directory or the current time if unknown.
-
- (Object) raw
(also: #to_s)
The raw list entry string.
-
- (Object) server_type
Returns the detected server type if this entry.
-
- (Boolean) symlink?
Looks like a symbolic link.
- - (Boolean) unknown?
Constructor Details
- (Entry) initialize(raw_ls_line, optional_attributes = {})
Create a new entry object. The additional argument is the list of metadata keys that can be used on the object. By default just takes and set the raw list entry.
Net::FTP::List.parse(raw_list_string) # => Net::FTP::List::Parser instance.
10 11 12 13 14 15 16 |
# File 'lib/net/ftp/list/entry.rb', line 10 def initialize(raw_ls_line, optional_attributes = {}) #:nodoc: @raw = raw_ls_line optional_attributes.each_pair do |key, value| raise ArgumentError, "#{key} is not supported" unless ALLOWED_ATTRIBUTES.include?(key) instance_variable_set("@#{key}", value) end end |
Instance Method Details
- (Fixnum) <=>(other)
Compares the receiver against another object.
38 39 40 41 42 43 44 45 |
# File 'lib/net/ftp/list/entry.rb', line 38 def <=>(other) if other.instance_of? self.class return self.filesize <=> other.filesize elsif other.instance_of? Fixnum or other.instance_of? Integer or other.instance_of? Float return self.filesize <=> other end raise ArgumentError.new('comparison of %s with %s failed!' % [self.class, other.class]) end |
- (Object) basename Also known as: name
The items basename (filename).
54 55 56 |
# File 'lib/net/ftp/list/entry.rb', line 54 def basename @basename ||= '' end |
- (Boolean) device?
Looks like a device.
76 77 78 |
# File 'lib/net/ftp/list/entry.rb', line 76 def device? !!(@device ||= false) end |
- (Boolean) dir? Also known as: directory?
Looks like a directory, try CWD.
60 61 62 |
# File 'lib/net/ftp/list/entry.rb', line 60 def dir? !!(@dir ||= false) end |
- (true, false) eql?(other)
Tests for objects equality (value and type).
24 25 26 27 28 29 |
# File 'lib/net/ftp/list/entry.rb', line 24 def eql?(other) return false if !other.instance_of? self.class return true if self.object_id == other.object_id self.raw == other.raw # if it's exactly the same line then the objects are the same end |
- (Boolean) file?
Looks like a file, try RETR.
66 67 68 |
# File 'lib/net/ftp/list/entry.rb', line 66 def file? !!(@file ||= false) end |
- (Object) filesize Also known as: size
Returns the filesize of the entry or 0 for directorties
86 87 88 |
# File 'lib/net/ftp/list/entry.rb', line 86 def filesize @filesize || 0 end |
- (Object) mtime
Returns the modification time of the file/directory or the current time if unknown
81 82 83 |
# File 'lib/net/ftp/list/entry.rb', line 81 def mtime @mtime || Time.now end |
- (Object) raw Also known as: to_s
The raw list entry string.
48 49 50 |
# File 'lib/net/ftp/list/entry.rb', line 48 def raw @raw ||= '' end |
- (Object) server_type
Returns the detected server type if this entry
92 93 94 |
# File 'lib/net/ftp/list/entry.rb', line 92 def server_type @server_type || "Unknown" end |
- (Boolean) symlink?
Looks like a symbolic link.
71 72 73 |
# File 'lib/net/ftp/list/entry.rb', line 71 def symlink? !!(@symlink ||= false) end |
- (Boolean) unknown?
96 97 98 |
# File 'lib/net/ftp/list/entry.rb', line 96 def unknown? @dir.nil? && @file.nil? && @symlink.nil? && @device.nil? end |