Class: Bcms::WebDAV::Path
- Inherits:
-
Object
- Object
- Bcms::WebDAV::Path
- Includes:
- Cms::Behaviors::Attaching::InstanceMethods
- Defined in:
- lib/bcms_webdav/resource.rb
Instance Method Summary collapse
- #file_name ⇒ Object
-
#initialize(path_as_string) ⇒ Path
constructor
Based on stackoverflow.com/questions/27745/getting-parts-of-a-url-regex Tested in rubular.com/.
- #parts ⇒ Object
- #path_without_filename ⇒ Object
- #sanitize_file_path(path) ⇒ Object
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.
228 229 230 231 232 233 234 235 |
# File 'lib/bcms_webdav/resource.rb', line 228 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_name ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/bcms_webdav/resource.rb', line 245 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 |
#parts ⇒ Object
241 242 243 |
# File 'lib/bcms_webdav/resource.rb', line 241 def parts @parts end |
#path_without_filename ⇒ Object
259 260 261 |
# File 'lib/bcms_webdav/resource.rb', line 259 def path_without_filename @string_path.gsub(file_name, '') end |
#sanitize_file_path(path) ⇒ Object
237 238 239 |
# File 'lib/bcms_webdav/resource.rb', line 237 def sanitize_file_path(path) Cms::Attachment.sanitize_file_path(path) end |