class Athena::MIME::Header::Collection
- Athena::MIME::Header::Collection
- Reference
- Object
Overview
Represents a collection of MIME headers.
Defined in:
header/collection.crConstructors
- .new(headers : Enumerable(AMIME::Header::Interface) = [] of AMIME::Header::Interface)
- .new(*headers : AMIME::Header::Interface)
Class Method Summary
-
.check_header_class(header : AMIME::Header::Interface) : Nil
Checks the provided header to ensure its name and type are compatible.
-
.unique_header?(name : String) : Bool
Returns
true
if the provided header name is required to be unique.
Instance Method Summary
-
#<<(header : AMIME::Header::Interface) : self
Adds the provided header to the collection.
-
#==(other : self)
Returns
true
if this reference is the same as other. -
#[](name : String, _type : T.class) : T forall T
Returns the first header with the provided name casted to type
T
. -
#[](name : String) : AMIME::Header::Interface
Returns the first header with the provided name.
-
#[]?(name : String, _type : T.class) : T | Nil forall T
Returns the first header with the provided name casted to type
T
, ornil
if no headers with that name exist. -
#[]?(name : String) : AMIME::Header::Interface | Nil
Returns the first header with the provided name, or
nil
if no headers with that name exist. -
#add_date_header(name : String, body : Time) : self
Adds an
AMIME::Header::Date
header to the collection with the provided name and body. -
#add_id_header(name : String, body : String | Array(String)) : self
Adds an
AMIME::Header::Identification
header to the collection with the provided name and body. -
#add_mailbox_header(name : String, body : AMIME::Address | String) : self
Adds an
AMIME::Header::Mailbox
header to the collection with the provided name and body. -
#add_mailbox_list_header(name : String, body : Enumerable(AMIME::Address | String)) : self
Adds an
AMIME::Header::MailboxList
header to the collection with the provided name and body. -
#add_parameterized_header(name : String, body : String, params : Hash(String, String) = {} of String => String) : self
Adds an
AMIME::Header::Parameterized
header to the collection with the provided name and body. -
#add_path_header(name : String, body : AMIME::Address | String) : self
Adds an
AMIME::Header::Path
header to the collection with the provided name and body. -
#add_text_header(name : String, body : String) : self
Adds an
AMIME::Header::Unstructured
header to the collection with the provided name and body. -
#all : Array(AMIME::Header::Interface)
Returns an array of all
AMIME::Header::Interface
instances stored within the collection. -
#all(name : String, & : AMIME::Header::Interface -> ) : Nil
Yields each
AMIME::Header::Interface
instance stored within the collection with the provided name. -
#all(& : AMIME::Header::Interface -> ) : Nil
Yields each
AMIME::Header::Interface
instance stored within the collection. -
#clone
Returns a copy of
self
with all instance variables cloned. -
#delete(name : String) : Nil
Removes the header(s) with the provided name from the collection.
-
#has_key?(name : String) : Bool
Returns
true
if the collection contains a header with the provided name, otherwisefalse
. -
#header_body(name : String)
Returns the body of the first header with the provided name.
-
#header_parameter(name : String, parameter : String) : String | Nil
Returns the value of the provided parameter for the first
AMIME::Header::Parameterized
header with the provided name. -
#line_length : Int32
Returns the
-
#line_length=(line_length : Int32) : Nil
Sets the max line length to use for this collection.
-
#names : Array(String)
Returns the names of all headers stored within the collection as an array of strings.
-
#to_a : Array(String)
Returns the string representation of each header in the collection as an array of strings.
Constructor Detail
Class Method Detail
Checks the provided header to ensure its name and type are compatible.
AMIME::Header::Collection.check_header_class AMIME::Header::Date.new("date", Time.utc) # => nil
AMIME::Header::Collection.check_header_class AMIME::Header::Unstructured.new("date", "blah")
# => AMIME::Exception::Logic: The 'date' header must be an instance of 'Athena::MIME::Header::Date' (got 'Athena::MIME::Header::Unstructured').
ameba:disable Metrics/CyclomaticComplexity:
Returns true
if the provided header name is required to be unique.
Instance Method Detail
Adds the provided header to the collection.
Returns true
if this reference is the same as other. Invokes same?
.
Returns the first header with the provided name casted to type T
.
Raises an AMIME::Exception::HeaderNotFound
exception if no header with that name exists.
Returns the first header with the provided name.
Raises an AMIME::Exception::HeaderNotFound
exception if no header with that name exists.
Returns the first header with the provided name casted to type T
, or nil
if no headers with that name exist.
Returns the first header with the provided name, or nil
if no headers with that name exist.
Adds an AMIME::Header::Date
header to the collection with the provided name and body.
Adds an AMIME::Header::Identification
header to the collection with the provided name and body.
Adds an AMIME::Header::Mailbox
header to the collection with the provided name and body.
Adds an AMIME::Header::MailboxList
header to the collection with the provided name and body.
Adds an AMIME::Header::Parameterized
header to the collection with the provided name and body.
Adds an AMIME::Header::Path
header to the collection with the provided name and body.
Adds an AMIME::Header::Unstructured
header to the collection with the provided name and body.
Returns an array of all AMIME::Header::Interface
instances stored within the collection.
Yields each AMIME::Header::Interface
instance stored within the collection with the provided name.
Yields each AMIME::Header::Interface
instance stored within the collection.
Returns true
if the collection contains a header with the provided name, otherwise false
.
Returns the value of the provided parameter for the first AMIME::Header::Parameterized
header with the provided name.
headers = AMIME::Header::Collection.new
headers.add_parameterized_header "content-type", "text/plain", {"charset" => "UTF-8"}
headers.header_parameter "content-type", "charset" # => "UTF-8"
Returns the names of all headers stored within the collection as an array of strings.
Returns the string representation of each header in the collection as an array of strings.