class AcceptHeaders::Encoding

Attributes

encoding[R]

Public Class Methods

new(encoding = '*', q: 1.0) click to toggle source
# File lib/accept_headers/encoding.rb, line 10
def initialize(encoding = '*', q: 1.0)
  self.encoding = encoding
  self.q = q
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/accept_headers/encoding.rb, line 15
def <=>(other)
  q <=> other.q
end
encoding=(value) click to toggle source
# File lib/accept_headers/encoding.rb, line 19
def encoding=(value)
  @encoding = value.strip.downcase
end
match(encoding_string) click to toggle source
# File lib/accept_headers/encoding.rb, line 35
def match(encoding_string)
  match_data = Negotiator::ENCODING_PATTERN.match(encoding_string)
  if !match_data
    false
  elsif encoding == match_data[:encoding]
    true
  elsif match_data[:encoding] == 'identity'
    true
  elsif encoding == '*'
    true
  else
    false
  end
end
to_h() click to toggle source
# File lib/accept_headers/encoding.rb, line 23
def to_h
  {
    encoding: encoding,
    q: q
  }
end
to_s() click to toggle source
# File lib/accept_headers/encoding.rb, line 30
def to_s
  qvalue = (q == 0 || q == 1) ? q.to_i : q
  "#{encoding};q=#{qvalue}"
end