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.
Instance Attribute Summary collapse
-
#basename ⇒ Object
(also: #name)
readonly
Returns the value of attribute basename.
-
#filesize ⇒ Object
(also: #size)
readonly
Returns the value of attribute filesize.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#raw ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute raw.
-
#server_type ⇒ Object
readonly
Returns the value of attribute server_type.
-
#symlink_destination ⇒ Object
readonly
Returns the value of attribute symlink_destination.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares the receiver against another object.
-
#device? ⇒ Boolean
Looks like a device.
-
#dir? ⇒ Boolean
(also: #directory?)
Looks like a directory, try CWD.
-
#eql?(other) ⇒ true, false
Tests for objects equality (value and type).
-
#file? ⇒ Boolean
Looks like a file, try RETR.
-
#initialize(raw_ls_line, basename: nil, type: nil, mtime: nil, filesize: nil, server_type: nil, symlink_destination: nil) ⇒ Entry
constructor
Create a new entry object.
-
#symlink? ⇒ Boolean
Looks like a symbolic link.
-
#unknown? ⇒ Boolean
Is the entry type unknown?.
Constructor Details
#initialize(raw_ls_line, basename: nil, type: nil, mtime: nil, filesize: nil, server_type: nil, symlink_destination: nil) ⇒ Entry
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/net/ftp/list/entry.rb', line 13 def initialize(raw_ls_line, basename: nil, type: nil, mtime: nil, filesize: nil, server_type: nil, symlink_destination: nil) #:nodoc: @raw = raw_ls_line.respond_to?(:force_encoding) ? raw_ls_line.force_encoding('utf-8') : raw_ls_line @basename = basename || '' @type = type @mtime = mtime || Time.now @filesize = filesize || 0 @server_type = server_type || 'Unknown' @symlink_destination = symlink_destination end |
Instance Attribute Details
#basename ⇒ Object (readonly) Also known as: name
Returns the value of attribute basename.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def basename @basename end |
#filesize ⇒ Object (readonly) Also known as: size
Returns the value of attribute filesize.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def filesize @filesize end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def mtime @mtime end |
#raw ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute raw.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def raw @raw end |
#server_type ⇒ Object (readonly)
Returns the value of attribute server_type.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def server_type @server_type end |
#symlink_destination ⇒ Object (readonly)
Returns the value of attribute symlink_destination.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def symlink_destination @symlink_destination end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/net/ftp/list/entry.rb', line 5 def type @type end |
Instance Method Details
#<=>(other) ⇒ Integer
Compares the receiver against another object.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/net/ftp/list/entry.rb', line 48 def <=>(other) case other when ::Net::FTP::List::Entry return filesize <=> other.filesize when Numeric return filesize <=> other end raise ArgumentError, format('comparison of %<self>s with %<other>s failed!', self: self.class, other: other.class) end |
#device? ⇒ Boolean
Looks like a device.
76 77 78 |
# File 'lib/net/ftp/list/entry.rb', line 76 def device? type == :device end |
#dir? ⇒ Boolean Also known as: directory?
Looks like a directory, try CWD.
60 61 62 |
# File 'lib/net/ftp/list/entry.rb', line 60 def dir? type == :dir end |
#eql?(other) ⇒ true, false
Tests for objects equality (value and type).
35 36 37 38 39 40 |
# File 'lib/net/ftp/list/entry.rb', line 35 def eql?(other) return false unless other.is_a?(::Net::FTP::List::Entry) return true if equal?(other) raw == other.raw # if it's exactly the same line then the objects are the same end |
#file? ⇒ Boolean
Looks like a file, try RETR.
66 67 68 |
# File 'lib/net/ftp/list/entry.rb', line 66 def file? type == :file end |
#symlink? ⇒ Boolean
Looks like a symbolic link.
71 72 73 |
# File 'lib/net/ftp/list/entry.rb', line 71 def symlink? type == :symlink end |
#unknown? ⇒ Boolean
Is the entry type unknown?
81 82 83 |
# File 'lib/net/ftp/list/entry.rb', line 81 def unknown? !dir? && !file? && !symlink? && !device? end |