Class: Peddler::Content
- Inherits:
-
Object
- Object
- Peddler::Content
- Defined in:
- lib/peddler/content.rb
Overview
Parses content metadata provided in the headers of a response
Instance Method Summary collapse
-
#charset ⇒ Encoding?
The character encoding of the response.
-
#length ⇒ String?
The size of the response body in bytes.
-
#md5 ⇒ String?
The MD5 digest of the response body.
-
#media_type ⇒ String?
The MIME type of the response.
-
#subtype ⇒ String?
The exact kind of data of the specified type the MIME type represents.
-
#type ⇒ String?
The general category into which the MIME type falls.
-
#xml? ⇒ Boolean?
Whether the response is an XML document.
Instance Method Details
#charset ⇒ Encoding?
The character encoding of the response
54 55 56 57 58 59 |
# File 'lib/peddler/content.rb', line 54 def charset match_data = headers['Content-Type']&.match(/charset=(.*);?/) return unless match_data Encoding.find(match_data[1]) end |
#length ⇒ String?
The size of the response body in bytes
16 17 18 19 20 |
# File 'lib/peddler/content.rb', line 16 def length return unless headers['Content-Length'] headers['Content-Length'].to_i end |
#md5 ⇒ String?
The MD5 digest of the response body
24 25 26 |
# File 'lib/peddler/content.rb', line 24 def md5 headers['Content-MD5'] end |
#media_type ⇒ String?
The MIME type of the response
30 31 32 33 34 |
# File 'lib/peddler/content.rb', line 30 def media_type return unless headers['Content-Type'] headers['Content-Type'].split(';').first end |
#subtype ⇒ String?
The exact kind of data of the specified type the MIME type represents
46 47 48 49 50 |
# File 'lib/peddler/content.rb', line 46 def subtype return unless media_type media_type.split('/').last end |
#type ⇒ String?
The general category into which the MIME type falls
38 39 40 41 42 |
# File 'lib/peddler/content.rb', line 38 def type return unless media_type media_type.split('/').first end |
#xml? ⇒ Boolean?
Whether the response is an XML document
63 64 65 66 67 |
# File 'lib/peddler/content.rb', line 63 def xml? return unless subtype subtype == 'xml' end |