Sha256: 7c348b14df11ab6fe7da2c57b36086f7f4308c1555f67fa528133e7b33b5676f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'net/ftp/list/parser'

module Net
  class FTP
    module List

      # Parse M$ like FTP LIST entries.
      #
      # == MATCHES
      #
      #   06-25-07  01:08PM       <DIR>          etc
      #   11-27-07  08:45PM                23437 README.TXT
      #
      # == SYNOPSIS
      #
      #   entry = Net::FTP::List::Microsoft.new('06-25-07  01:08PM       <DIR>          etc')
      #   entry.dir?     # => true
      #   entry.basename # => 'etc'
      class Microsoft < 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{
          ^\s*
          (\S+)\s+(\S+)\s+
          (?:(<DIR>)|([0-9]+))\s+
          (\S.*)
          \s*$
        }x

        # Parse a M$ like FTP LIST entries.
        def initialize(raw)
          super(raw)
          match = REGEXP.match(raw.strip) or raise ParserError

          if match[3] == '<DIR>'
            @dir = true
          else
            @file = true
          end

          # TODO: Permissions, users, groups, date/time.

          @basename = match[5]
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-ftp-list-0.7 lib/net/ftp/list/microsoft.rb