Class: Bcms::WebDAV::Path

Inherits:
Object
  • Object
show all
Includes:
Cms::Behaviors::Attaching::InstanceMethods
Defined in:
lib/bcms_webdav/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_as_string) ⇒ Path

Based on stackoverflow.com/questions/27745/getting-parts-of-a-url-regex Tested in rubular.com/

This will also convert paths with spaces, etc, into CMS style sanatized paths.



201
202
203
204
205
206
207
208
# File 'lib/bcms_webdav/resource.rb', line 201

def initialize(path_as_string)

  @string_path = sanitize_file_path(CGI::unescape(path_as_string))
  Rails.logger.warn "Sanitized path is: " + @string_path
  @regex = /^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/
  scanned = @string_path.scan(@regex)
  @parts = scanned[0]
end

Instance Method Details

#file_nameObject



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/bcms_webdav/resource.rb', line 214

def file_name
  return @parts[5] if @parts # Most longer URLs

  # i.e. /somefilename.jpg
  if @parts == nil
    if @string_path.starts_with?("/") && @string_path.count("/") == 1
      return @string_path.gsub("/", '')
    end

    # i.e. somefilename.jpg
    return @string_path
  end
end

#partsObject



210
211
212
# File 'lib/bcms_webdav/resource.rb', line 210

def parts
  @parts
end

#path_without_filenameObject



228
229
230
# File 'lib/bcms_webdav/resource.rb', line 228

def path_without_filename
  @string_path.gsub(file_name, '')
end