Class: Net::FTP::List::Microsoft
- Inherits:
-
Parser
- Object
- Parser
- Net::FTP::List::Microsoft
- Defined in:
- lib/net/ftp/list/microsoft.rb
Overview
Parse Microsoft(NT) like FTP LIST entries.
MATCHES
06-25-2007 01:08PM <DIR> etc
06-25-07 01:08PM <DIR> etc
11-27-07 08:45PM 23437 README.TXT
Constant Summary collapse
- REGEXP =
%r! ^\s* ([0-9\-:/]{5,})\s+([0-9\-:]{3,}(?:[aApP][mM])?)\s+ (?:(<DIR>)|([0-9]+))\s+ (\S.*) \s*$ !x.freeze
Class Method Summary collapse
-
.parse(raw, timezone: :utc) ⇒ Object
Parse a Microsoft(NT) like FTP LIST entries.
Class Method Details
.parse(raw, timezone: :utc) ⇒ Object
Parse a Microsoft(NT) like FTP LIST entries.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/net/ftp/list/microsoft.rb', line 21 def self.parse(raw, timezone: :utc) match = REGEXP.match(raw.strip) or return false date_match = /(\d\d).(\d\d).(\d\d(?:\d\d)?)/.match(match[1]) date_format = date_match[1].to_i > 12 ? '%d-%m-%y' : '%m-%d-%y' date_format.sub!(/%y/, '%Y') if date_match[3].length > 2 unless /-/.match?(match[1]) date_format.tr!('-', '/') if %r{/}.match?(match[1]) date_format.tr!('-', ':') if /:/.match?(match[1]) end mtime = parse_time("#{match[1]} #{match[2]}", format: "#{date_format} %H:%M%p", timezone: timezone) type = match[3] == '<DIR>' ? :dir : :file emit_entry( raw, type: type, filesize: match[4].to_i, basename: match[5], mtime: mtime, ) end |