Class: HTTP::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/http/content_type.rb

Constant Summary collapse

MIME_TYPE_RE =
%r{^([^/]+/[^;]+)(?:$|;)}
CHARSET_RE =
/;\s*charset=([^;]+)/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mime_type = nil, charset = nil) ⇒ ContentType

Returns a new instance of ContentType.



29
30
31
32
# File 'lib/http/content_type.rb', line 29

def initialize(mime_type = nil, charset = nil)
  @mime_type = mime_type
  @charset   = charset
end

Instance Attribute Details

#charsetObject

Returns the value of attribute charset.



8
9
10
# File 'lib/http/content_type.rb', line 8

def charset
  @charset
end

#mime_typeObject

Returns the value of attribute mime_type.



8
9
10
# File 'lib/http/content_type.rb', line 8

def mime_type
  @mime_type
end

Class Method Details

.parse(str) ⇒ Object

Parse string and return ContentType struct



12
13
14
# File 'lib/http/content_type.rb', line 12

def parse(str)
  new mime_type(str), charset(str)
end