Class: Rack::ContentDispositionHelper::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/content_disposition_helper/converter.rb

Constant Summary collapse

LIMIT =
254
FILENAME_ASTERISK_PREFIX =
"filename*=UTF-8''"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_value) ⇒ Converter

Returns a new instance of Converter.



13
14
15
16
# File 'lib/rack/content_disposition_helper/converter.rb', line 13

def initialize(original_value)
  @original_value = original_value
  @parts = original_value&.split
end

Instance Attribute Details

#original_valueObject (readonly)

Returns the value of attribute original_value.



11
12
13
# File 'lib/rack/content_disposition_helper/converter.rb', line 11

def original_value
  @original_value
end

#partsObject (readonly)

Returns the value of attribute parts.



11
12
13
# File 'lib/rack/content_disposition_helper/converter.rb', line 11

def parts
  @parts
end

Instance Method Details

#convertObject



28
29
30
31
32
# File 'lib/rack/content_disposition_helper/converter.rb', line 28

def convert
  return original_value if !disposition || !raw_filename

  "#{disposition} filename=\"#{raw_filename}\""
end

#dispositionObject



24
25
26
# File 'lib/rack/content_disposition_helper/converter.rb', line 24

def disposition
  parts&.first
end

#filename_asteriskObject



38
39
40
# File 'lib/rack/content_disposition_helper/converter.rb', line 38

def filename_asterisk
  parts&.find { |d| d.start_with?(FILENAME_ASTERISK_PREFIX) }
end

#length_limit_exceeded?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rack/content_disposition_helper/converter.rb', line 18

def length_limit_exceeded?
  return nil unless original_value

  original_value.length > LIMIT
end

#raw_filenameObject



34
35
36
# File 'lib/rack/content_disposition_helper/converter.rb', line 34

def raw_filename
  @raw_filename ||= filename_asterisk&.then { |v| CGI.unescape(v).delete_prefix!(FILENAME_ASTERISK_PREFIX) }
end