class

Athena::Negotiation::AbstractNegotiator(HeaderType)

Inherits Reference < Object

Base negotiator type. Implements logic common to all negotiators.

Instance methods

best(header : String, priorities : Indexable(String), strict : Bool = false) : HeaderType | Nil

Returns the best HeaderType based on the provided header value and priorities.

If strict is true, an ANG::Exception::Exception will be raised if the header contains an invalid value, otherwise it is ignored.

See Athena::Negotiation for examples.

Source
ordered_elements(header : String) : Array(HeaderType)

Returns an array of HeaderType that the provided header allows, ordered so that the #best match is first.

header = "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5"

ordered_elements = ANG.negotiator.ordered_elements header

ordered_elements[0].media_range # => "text/html"
ordered_elements[1].media_range # => "text/html"
ordered_elements[2].media_range # => "*/*"
ordered_elements[3].media_range # => "text/html"
ordered_elements[4].media_range # => "text/*"
Source