Class: Xenon::ContentType
- Inherits:
-
Object
- Object
- Xenon::ContentType
- Defined in:
- lib/xenon/media_type.rb
Overview
A content type.
Constant Summary collapse
- DEFAULT_CHARSET =
historically iso-8859-1 but see tools.ietf.org/html/rfc7231#appendix-B
'utf-8'
Instance Attribute Summary collapse
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#media_type ⇒ Object
readonly
Returns the value of attribute media_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(media_type, charset = DEFAULT_CHARSET) ⇒ ContentType
constructor
A new instance of ContentType.
- #to_s ⇒ Object
Constructor Details
#initialize(media_type, charset = DEFAULT_CHARSET) ⇒ ContentType
Returns a new instance of ContentType.
93 94 95 96 |
# File 'lib/xenon/media_type.rb', line 93 def initialize(media_type, charset = DEFAULT_CHARSET) @media_type = media_type @charset = charset end |
Instance Attribute Details
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
89 90 91 |
# File 'lib/xenon/media_type.rb', line 89 def charset @charset end |
#media_type ⇒ Object (readonly)
Returns the value of attribute media_type.
89 90 91 |
# File 'lib/xenon/media_type.rb', line 89 def media_type @media_type end |
Class Method Details
.parse(s) ⇒ Object
98 99 100 101 102 |
# File 'lib/xenon/media_type.rb', line 98 def self.parse(s) media_type = MediaType.parse(s) charset = media_type.params.delete('charset') || DEFAULT_CHARSET ContentType.new(media_type, charset) end |
Instance Method Details
#to_s ⇒ Object
104 105 106 |
# File 'lib/xenon/media_type.rb', line 104 def to_s "#{@media_type}; charset=#{@charset}" end |