class Athena::MIME::Header::Collection

Overview

Represents a collection of MIME headers.

Defined in:

header/collection.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(headers : Enumerable(AMIME::Header::Interface) = [] of AMIME::Header::Interface) #

[View source]
def self.new(*headers : AMIME::Header::Interface) #

[View source]

Class Method Detail

def self.check_header_class(header : AMIME::Header::Interface) : Nil #

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:


[View source]
def self.unique_header?(name : String) : Bool #

Returns true if the provided header name is required to be unique.


[View source]

Instance Method Detail

def <<(header : AMIME::Header::Interface) : self #

Adds the provided header to the collection.


[View source]
def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def [](name : String, _type : T.class) : T forall T #

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.


[View source]
def [](name : String) : AMIME::Header::Interface #

Returns the first header with the provided name. Raises an AMIME::Exception::HeaderNotFound exception if no header with that name exists.


[View source]
def []?(name : String, _type : T.class) : T | Nil forall T #

Returns the first header with the provided name casted to type T, or nil if no headers with that name exist.


[View source]
def []?(name : String) : AMIME::Header::Interface | Nil #

Returns the first header with the provided name, or nil if no headers with that name exist.


[View source]
def add_date_header(name : String, body : Time) : self #

Adds an AMIME::Header::Date header to the collection with the provided name and body.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def add_text_header(name : String, body : String) : self #

Adds an AMIME::Header::Unstructured header to the collection with the provided name and body.


[View source]
def all : Array(AMIME::Header::Interface) #

Returns an array of all AMIME::Header::Interface instances stored within the collection.


[View source]
def all(name : String, & : AMIME::Header::Interface -> ) : Nil #

Yields each AMIME::Header::Interface instance stored within the collection with the provided name.


[View source]
def all(& : AMIME::Header::Interface -> ) : Nil #

Yields each AMIME::Header::Interface instance stored within the collection.


[View source]
def clone #

Returns a copy of self with all instance variables cloned.


[View source]
def delete(name : String) : Nil #

Removes the header(s) with the provided name from the collection.


[View source]
def has_key?(name : String) : Bool #

Returns true if the collection contains a header with the provided name, otherwise false.


[View source]
def header_body(name : String) #

Returns the body of the first header with the provided name.


[View source]
def 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.

headers = AMIME::Header::Collection.new
headers.add_parameterized_header "content-type", "text/plain", {"charset" => "UTF-8"}
headers.header_parameter "content-type", "charset" # => "UTF-8"

[View source]
def line_length : Int32 #

Returns the


[View source]
def line_length=(line_length : Int32) : Nil #

Sets the max line length to use for this collection.


[View source]
def names : Array(String) #

Returns the names of all headers stored within the collection as an array of strings.


[View source]
def to_a : Array(String) #

Returns the string representation of each header in the collection as an array of strings.


[View source]