class ActiveStorage::Filename::Parameters

Constants

RFC_5987_ESCAPED_CHAR
TRADITIONAL_ESCAPED_CHAR

Attributes

filename[R]

Public Class Methods

new(filename) click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 6
def initialize(filename)
  @filename = filename
end

Public Instance Methods

ascii() click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 16
def ascii
  'filename="' + percent_escape(I18n.transliterate(filename.sanitized), TRADITIONAL_ESCAPED_CHAR) + '"'
end
combined() click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 10
def combined
  "#{ascii}; #{utf8}"
end
to_s() click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 26
def to_s
  combined
end
utf8() click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 22
def utf8
  "filename*=UTF-8''" + percent_escape(filename.sanitized, RFC_5987_ESCAPED_CHAR)
end

Private Instance Methods

percent_escape(string, pattern) click to toggle source
# File activestorage/app/models/active_storage/filename/parameters.rb, line 31
def percent_escape(string, pattern)
  string.gsub(pattern) do |char|
    char.bytes.map { |byte| "%%%02X" % byte }.join
  end
end