Class: Zero::Request::AcceptType

Inherits:
Object
  • Object
show all
Defined in:
lib/zero/request/accept_type.rb

Overview

This class provides an interface to access information of accept schemas.

Constant Summary collapse

MEDIA_TYPE_SEPERATOR =
','
MEDIA_PARAM_SEPERATOR =
';'
MEDIA_QUALITY_REGEX =
/q=[01]\./

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ AcceptType

create a new instance of AcceptType



10
11
12
13
14
15
16
# File 'lib/zero/request/accept_type.rb', line 10

def initialize(string)
  if string.nil?
    @elements = []
  else
    @elements = parse_elements(string)
  end
end

Instance Method Details

#eachObject

iterate over all media types



25
26
27
# File 'lib/zero/request/accept_type.rb', line 25

def each
  @elements.each {|element| yield element}
end

#preferredObject

return the preferred type

Returns:

  • String the preferred media type



20
21
22
# File 'lib/zero/request/accept_type.rb', line 20

def preferred
  @elements.first
end