Class: InternetMessage::ContentType
- Inherits:
-
Object
- Object
- InternetMessage::ContentType
- Defined in:
- lib/internet_message/content_type.rb
Constant Summary collapse
- TOKEN_RE =
/[0-9a-zA-Z\!\#\$\%\&\'\*\+\-\.\^\_\`\{\|\}\~]+/i
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compare self and other.
-
#initialize(type, subtype, attribute = {}) ⇒ ContentType
constructor
A new instance of ContentType.
Constructor Details
#initialize(type, subtype, attribute = {}) ⇒ ContentType
Returns a new instance of ContentType.
27 28 29 |
# File 'lib/internet_message/content_type.rb', line 27 def initialize(type, subtype, attribute={}) @type, @subtype, @attribute = type.downcase, subtype.downcase, attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
22 23 24 |
# File 'lib/internet_message/content_type.rb', line 22 def attribute @attribute end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
22 23 24 |
# File 'lib/internet_message/content_type.rb', line 22 def subtype @subtype end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/internet_message/content_type.rb', line 22 def type @type end |
Class Method Details
.parse(src) ⇒ ContentType
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/internet_message/content_type.rb', line 11 def self.parse(src) tokens = src.is_a?(String) ? Tokenizer.new(src, :token_re=>TOKEN_RE).tokenize : src.dup tokens.delete_if{|t| t.type == :WSP or t.type == :COMMENT} unless tokens.size >= 3 && tokens[0].type == :TOKEN && tokens[1].value == '/' && tokens[2].type == :TOKEN return nil end type, subtype = tokens[0].value, tokens[2].value tokens.shift 3 ContentType.new(type, subtype, ContentAttribute.parse_attribute(tokens)) end |
Instance Method Details
#==(other) ⇒ true, false
Compare self and other
34 35 36 |
# File 'lib/internet_message/content_type.rb', line 34 def ==(other) other.is_a?(ContentType) && other.type == self.type && other.subtype == self.subtype && other.attribute == self.attribute end |