Class: Mail::ContentTypeElement

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/mail/elements/content_type_element.rb

Overview

:nodoc:

Constant Summary

Constants included from Patterns

Patterns::ATOM_UNSAFE, Patterns::CONTROL_CHAR, Patterns::CRLF, Patterns::FIELD_BODY, Patterns::FIELD_LINE, Patterns::FIELD_NAME, Patterns::FWS, Patterns::HEADER_LINE, Patterns::PHRASE_UNSAFE, Patterns::QP_SAFE, Patterns::QP_UNSAFE, Patterns::TEXT, Patterns::TOKEN_UNSAFE, Patterns::WSP

Instance Method Summary collapse

Methods included from Utilities

#atom_safe?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, #token_safe?, #unbracket, #underscoreize, #unparen, #unquote, #uri_escape, #uri_parser, #uri_unescape

Constructor Details

#initialize(string) ⇒ ContentTypeElement

Returns a new instance of ContentTypeElement.


7
8
9
10
11
12
13
14
15
16
# File 'lib/mail/elements/content_type_element.rb', line 7

def initialize( string )
  parser = Mail::ContentTypeParser.new
  if tree = parser.parse(cleaned(string))
    @main_type = tree.main_type.text_value.downcase
    @sub_type = tree.sub_type.text_value.downcase
    @parameters = tree.parameters
  else
    raise Mail::Field::ParseError.new(ContentTypeElement, string, parser.failure_reason)
  end
end

Instance Method Details

#cleaned(string) ⇒ Object


30
31
32
# File 'lib/mail/elements/content_type_element.rb', line 30

def cleaned(string)
  string =~ /(.+);\s*$/ ? $1 : string
end

#main_typeObject


18
19
20
# File 'lib/mail/elements/content_type_element.rb', line 18

def main_type
  @main_type
end

#parametersObject


26
27
28
# File 'lib/mail/elements/content_type_element.rb', line 26

def parameters
  @parameters
end

#sub_typeObject


22
23
24
# File 'lib/mail/elements/content_type_element.rb', line 22

def sub_type
  @sub_type
end