Class: Rack::Prefer::PreferPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/prefer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ PreferPresenter

Returns a new instance of PreferPresenter.


8
9
10
11
12
13
14
15
16
17
# File 'lib/rack/prefer.rb', line 8

def initialize(req)
  @values = CGI.parse(
    (req.env['HTTP_PREFER'] || '').gsub(',','&').gsub(' ','')
  )
  @values = {} if !@values.is_a?(Hash)
  @values.each{|k,v| @values[k] = v.first}
  if Object.const_defined?(:HashWithIndifferentAccess)
    @values = HashWithIndifferentAccess.new(@values)
  end
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.


6
7
8
# File 'lib/rack/prefer.rb', line 6

def values
  @values
end

Instance Method Details

#handlingObject


43
44
45
# File 'lib/rack/prefer.rb', line 43

def handling
  @values['handling']
end

#handling_lanient?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/rack/prefer.rb', line 51

def handling_lanient?
  @values['handling'] == 'lanient'
end

#handling_strict?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/rack/prefer.rb', line 47

def handling_strict?
  @values['handling'] == 'strict'
end

#respond_async?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/rack/prefer.rb', line 27

def respond_async?
  @values.key?('respond-async')
end

#returnObject


31
32
33
# File 'lib/rack/prefer.rb', line 31

def return
  @values['return']
end

#return_minimal?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/rack/prefer.rb', line 39

def return_minimal?
  @values['return'] == 'minimal'
end

#return_representaton?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/rack/prefer.rb', line 35

def return_representaton?
  @values['return'] == 'representation'
end

#waitObject


23
24
25
# File 'lib/rack/prefer.rb', line 23

def wait
  @values['wait'].to_i
end

#wait?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/rack/prefer.rb', line 19

def wait?
  @values.key?('wait')
end