Sha256: 91f3fb1afbfdc85c33ed60988f220776b658e56887e38d6a8c6a2561201ba820

Contents?: true

Size: 720 Bytes

Versions: 3

Compression:

Stored size: 720 Bytes

Contents

require "accept_headers/acceptable"

module AcceptHeaders
  class Encoding
    include Comparable
    include Acceptable

    attr_reader :encoding

    def initialize(encoding = '*', q: 1.0)
      self.encoding = encoding
      self.q = q
    end

    def <=>(other)
      q <=> other.q
    end

    def encoding=(value)
      @encoding = value.strip.downcase
    end

    def to_h
      {
        encoding: encoding,
        q: q
      }
    end

    def to_s
      qvalue = (q == 0 || q == 1) ? q.to_i : q
      "#{encoding};q=#{qvalue}"
    end

    def match(other)
      if encoding == other.encoding
        true
      elsif other.encoding == '*'
        true
      else
        false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
accept_headers-0.0.4 lib/accept_headers/encoding.rb
accept_headers-0.0.3 lib/accept_headers/encoding.rb
accept_headers-0.0.2 lib/accept_headers/encoding.rb