Class: ContentDisposition
- Inherits:
-
Object
- Object
- ContentDisposition
- Defined in:
- lib/content_disposition.rb,
lib/content_disposition/version.rb
Constant Summary collapse
- ATTACHMENT =
"attachment"- INLINE =
"inline"- DEFAULT_TO_ASCII =
->(filename) do filename.encode("US-ASCII", undef: :replace, replace: "?") end
- TRADITIONAL_ESCAPED_CHAR =
/[^ A-Za-z0-9!#$+.^_`|~-]/- RFC_5987_ESCAPED_CHAR =
/[^A-Za-z0-9!#$&+.^_`|~-]/- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.to_ascii ⇒ Object
Returns the value of attribute to_ascii.
Instance Attribute Summary collapse
-
#disposition ⇒ Object
readonly
Returns the value of attribute disposition.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#to_ascii ⇒ Object
readonly
Returns the value of attribute to_ascii.
Class Method Summary collapse
- .attachment(filename = nil) ⇒ Object
- .format(**options) ⇒ Object (also: call)
- .inline(filename = nil) ⇒ Object
Instance Method Summary collapse
- #ascii_filename ⇒ Object
-
#initialize(disposition:, filename:, to_ascii: nil) ⇒ ContentDisposition
constructor
A new instance of ContentDisposition.
- #to_s ⇒ Object
- #utf8_filename ⇒ Object
Constructor Details
#initialize(disposition:, filename:, to_ascii: nil) ⇒ ContentDisposition
Returns a new instance of ContentDisposition.
32 33 34 35 36 37 38 39 40 |
# File 'lib/content_disposition.rb', line 32 def initialize(disposition:, filename:, to_ascii: nil) unless [ATTACHMENT, INLINE].include?(disposition.to_s) fail ArgumentError, "unknown disposition: #{disposition.inspect}" end @disposition = disposition @filename = filename @to_ascii = to_ascii || self.class.to_ascii || DEFAULT_TO_ASCII end |
Class Attribute Details
.to_ascii ⇒ Object
Returns the value of attribute to_ascii.
27 28 29 |
# File 'lib/content_disposition.rb', line 27 def to_ascii @to_ascii end |
Instance Attribute Details
#disposition ⇒ Object (readonly)
Returns the value of attribute disposition.
30 31 32 |
# File 'lib/content_disposition.rb', line 30 def disposition @disposition end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
30 31 32 |
# File 'lib/content_disposition.rb', line 30 def filename @filename end |
#to_ascii ⇒ Object (readonly)
Returns the value of attribute to_ascii.
30 31 32 |
# File 'lib/content_disposition.rb', line 30 def to_ascii @to_ascii end |
Class Method Details
.attachment(filename = nil) ⇒ Object
14 15 16 |
# File 'lib/content_disposition.rb', line 14 def (filename = nil) format(disposition: ATTACHMENT, filename: filename) end |
.format(**options) ⇒ Object Also known as: call
22 23 24 |
# File 'lib/content_disposition.rb', line 22 def format(**) new(**).to_s end |
.inline(filename = nil) ⇒ Object
18 19 20 |
# File 'lib/content_disposition.rb', line 18 def inline(filename = nil) format(disposition: INLINE, filename: filename) end |
Instance Method Details
#ascii_filename ⇒ Object
52 53 54 |
# File 'lib/content_disposition.rb', line 52 def ascii_filename 'filename="' + percent_escape(to_ascii[filename], TRADITIONAL_ESCAPED_CHAR) + '"' end |
#to_s ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/content_disposition.rb', line 42 def to_s if filename "#{disposition}; #{ascii_filename}; #{utf8_filename}" else "#{disposition}" end end |
#utf8_filename ⇒ Object
58 59 60 |
# File 'lib/content_disposition.rb', line 58 def utf8_filename "filename*=UTF-8''" + percent_escape(filename, RFC_5987_ESCAPED_CHAR) end |