Class: Protocol::HTTP::Header::Accept::MediaRange

Inherits:
Struct
  • Object
show all
Defined in:
lib/protocol/http/header/accept.rb

Overview

A single entry in the Accept: header, which includes a mime type and associated parameters. A media range can include wild cards, but a media type is a specific type and subtype.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, subtype = "*", parameters = {}) ⇒ MediaRange

Create a new media range.



38
39
40
# File 'lib/protocol/http/header/accept.rb', line 38

def initialize(type, subtype = "*", parameters = {})
	super(type, subtype, parameters)
end

Instance Attribute Details

#parametersObject

Returns the value of attribute parameters

Returns:

  • (Object)

    the current value of parameters



32
33
34
# File 'lib/protocol/http/header/accept.rb', line 32

def parameters
  @parameters
end

#subtypeObject

Returns the value of attribute subtype

Returns:

  • (Object)

    the current value of subtype



32
33
34
# File 'lib/protocol/http/header/accept.rb', line 32

def subtype
  @subtype
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



32
33
34
# File 'lib/protocol/http/header/accept.rb', line 32

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Compare the media range with another media range or a string, based on the quality factor.



43
44
45
# File 'lib/protocol/http/header/accept.rb', line 43

def <=> other
	other.quality_factor <=> self.quality_factor
end

#quality_factorObject

The quality factor associated with the media range, which is used to determine the order of preference.



65
66
67
# File 'lib/protocol/http/header/accept.rb', line 65

def quality_factor
	parameters.fetch("q", 1.0).to_f
end

#to_sObject Also known as: to_str

The string representation of the media range, including the type, subtype, and any parameters.



56
57
58
# File 'lib/protocol/http/header/accept.rb', line 56

def to_s
	"#{type}/#{subtype}#{parameters_string}"
end