Class: GdsApi::Response::CacheControl

Inherits:
Hash
  • Object
show all
Defined in:
lib/gds_api/response.rb

Constant Summary collapse

PATTERN =
/([-a-z]+)(?:\s*=\s*([^,\s]+))?,?+/i

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ CacheControl

Returns a new instance of CacheControl.



26
27
28
29
# File 'lib/gds_api/response.rb', line 26

def initialize(value = nil)
  super()
  parse(value)
end

Instance Method Details

#max_ageObject



55
56
57
# File 'lib/gds_api/response.rb', line 55

def max_age
  self["max-age"].to_i if key?("max-age")
end

#must_revalidate?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/gds_api/response.rb', line 47

def must_revalidate?
  self["must-revalidate"]
end

#no_cache?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/gds_api/response.rb', line 39

def no_cache?
  self["no-cache"]
end

#no_store?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/gds_api/response.rb', line 43

def no_store?
  self["no-store"]
end

#private?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gds_api/response.rb', line 35

def private?
  self["private"]
end

#proxy_revalidate?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/gds_api/response.rb', line 51

def proxy_revalidate?
  self["proxy-revalidate"]
end

#public?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gds_api/response.rb', line 31

def public?
  self["public"]
end

#reverse_max_ageObject Also known as: r_maxage



59
60
61
# File 'lib/gds_api/response.rb', line 59

def reverse_max_age
  self["r-maxage"].to_i if key?("r-maxage")
end

#shared_max_ageObject Also known as: s_maxage



64
65
66
# File 'lib/gds_api/response.rb', line 64

def shared_max_age
  self["s-maxage"].to_i if key?("r-maxage")
end

#to_sObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gds_api/response.rb', line 69

def to_s
  directives = []
  values = []

  each do |key, value|
    if value == true
      directives << key
    elsif value
      values << "#{key}=#{value}"
    end
  end

  (directives.sort + values.sort).join(", ")
end