lib/net/ftp/list/netware.rb in net-ftp-list-2.1.1 vs lib/net/ftp/list/netware.rb in net-ftp-list-3.2.0
- old
+ new
@@ -1,54 +1,35 @@
require 'net/ftp/list/parser'
require 'time'
-module Net
- class FTP
- module List
+# Parse Netware like FTP LIST entries.
+#
+# == MATCHES
+#
+# d [RWCEAFMS] dpearce 512 Jun 27 23:46 public.www
+class Net::FTP::List::Netware < Net::FTP::List::Parser
+ # Stolen straight from the ASF's commons Java FTP LIST parser library.
+ # http://svn.apache.org/repos/asf/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/
+ REGEXP = %r!^
+ (d|-){1}\s+
+ \[(.*?)\]\s+
+ (\S+)\s+(\d+)\s+
+ (\S+\s+\S+\s+((\d+:\d+)|(\d{4})))
+ \s+(.*)
+ $!x
- # Parse Netware like FTP LIST entries.
- #
- # == MATCHES
- #
- # d [RWCEAFMS] dpearce 512 Jun 27 23:46 public.www
- #
- # == SYNOPSIS
- #
- # entry = Net::FTP::List::Netware.new('d [RWCEAFMS] dpearce 512 Jun 27 23:46 public.www')
- # entry.dir? # => true
- # entry.basename # => 'public.www'
- class Netware < Parser
+ # Parse a Netware like FTP LIST entries.
+ def self.parse(raw)
+ match = REGEXP.match(raw.strip) or return false
- # Stolen straight from the ASF's commons Java FTP LIST parser library.
- # http://svn.apache.org/repos/asf/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/
+ is_dir = match[1] == 'd'
- REGEXP = %r!^
- (d|-){1}\s+
- \[(.*?)\]\s+
- (\S+)\s+(\d+)\s+
- (\S+\s+\S+\s+((\d+:\d+)|(\d{4})))
- \s+(.*)
- $!x
-
- # Parse a Netware like FTP LIST entries.
- def initialize(raw)
- super(raw)
- match = REGEXP.match(raw.strip) or raise ParserError
-
- @mtime = Time.parse(match[5])
- @filesize = match[4].to_i
-
- if match[1] == 'd'
- @dir = true
- else
- @file = true
- end
-
- # TODO: Permissions, users, groups, date/time.
-
- @basename = match[9]
- end
- end
-
- end
+ emit_entry(
+ raw,
+ :mtime => Time.parse(match[5]),
+ :filesize => match[4].to_i,
+ :dir => is_dir,
+ :file => !is_dir,
+ :basename => match[9]
+ )
end
end