Sha256: edf200ea06a482299512d54af425422d8dc5e19dc49e6c25931c93da9dae99d5

Contents?: true

Size: 1014 Bytes

Versions: 24

Compression:

Stored size: 1014 Bytes

Contents

module RestFtpDaemon
  class Path
    attr_accessor :name
    attr_accessor :dir

    def initialize full, strip_leading_slash = false
      # Extract path parts
      @name = extract_filename full.to_s
      @dir = extract_dirname full.to_s

      # Remove leading slash if needed
      strip_leading_slash_from_dir! if strip_leading_slash
    end

    def full
      if @dir.nil? || @dir.empty?
        return @name
      else
        return File.join @dir, @name
      end
    end

    def size
      File.size full if File.exist? full
    end

  private

    def extract_filename path
      # match everything that's after a slash at the end of the string
      m = path.match(/\/?([^\/]+)$/)
      return m[1].to_s unless m.nil?
    end

    def extract_dirname path
      # match all the beginning of the string up to the last slash
      m = path.match(/^(.*)\/[^\/]*$/)
      return m[1].to_s unless m.nil?
    end

    def strip_leading_slash_from_dir!
      @dir.to_s.gsub!(/^\//, '')
    end

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.302.3 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.302.2 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.302.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.302.0 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.300.3 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.300.2 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.300.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.250.5 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.250.4 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.250.3 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.250.0 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.247.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.247.0 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.246.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.246.0 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.245.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.245 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.243.2 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.243.1 lib/rest-ftp-daemon/path.rb
rest-ftp-daemon-0.243 lib/rest-ftp-daemon/path.rb