Class: Rack::ContentDispositionHelper::Converter
- Inherits:
-
Object
- Object
- Rack::ContentDispositionHelper::Converter
- Defined in:
- lib/rack/content_disposition_helper/converter.rb
Constant Summary collapse
- LIMIT =
254
- FILENAME_ASTERISK_PREFIX =
"filename*=UTF-8''"
Instance Attribute Summary collapse
-
#original_value ⇒ Object
readonly
Returns the value of attribute original_value.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #convert ⇒ Object
- #disposition ⇒ Object
- #filename_asterisk ⇒ Object
-
#initialize(original_value) ⇒ Converter
constructor
A new instance of Converter.
- #length_limit_exceeded? ⇒ Boolean
- #raw_filename ⇒ Object
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_value ⇒ Object (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 |
#parts ⇒ Object (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
#convert ⇒ Object
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 |
#disposition ⇒ Object
24 25 26 |
# File 'lib/rack/content_disposition_helper/converter.rb', line 24 def disposition parts&.first end |
#filename_asterisk ⇒ Object
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
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_filename ⇒ Object
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 |