Class: Imap::Backup::Naming
- Inherits:
-
Object
- Object
- Imap::Backup::Naming
- Defined in:
- lib/imap/backup/naming.rb
Overview
Maps between server and file system folder names ‘/` is treated as an acceptable character
Constant Summary collapse
- INVALID_FILENAME_CHARACTERS =
The characters that cannot be used in file names
":%;".freeze
- INVALID_FILENAME_CHARACTER_MATCH =
A regular expression that captures each disallowed character
/([#{INVALID_FILENAME_CHARACTERS}])/
Class Method Summary collapse
-
.from_local_path(name) ⇒ Object
The supplied string with hexadecimal codes (‘%xx’) replaced with the characters they represent.
-
.to_local_path(name) ⇒ String
The supplied string iwth disallowed characters replaced by their hexadecimal representation.
Class Method Details
.from_local_path(name) ⇒ Object
Returns the supplied string with hexadecimal codes (‘%xx’) replaced with the characters they represent.
28 29 30 31 32 33 34 |
# File 'lib/imap/backup/naming.rb', line 28 def self.from_local_path(name) name.gsub(/%(.*?);/) do ::Regexp.last_match(1). to_i(16). chr("UTF-8") end end |
.to_local_path(name) ⇒ String
Returns the supplied string iwth disallowed characters replaced by their hexadecimal representation.
15 16 17 18 19 20 21 22 23 |
# File 'lib/imap/backup/naming.rb', line 15 def self.to_local_path(name) name.gsub(INVALID_FILENAME_CHARACTER_MATCH) do |character| hex = character. codepoints[0]. to_s(16) "%#{hex};" end end |