class Drillbit::AcceptHeader

Attributes

application[RW]
raw_accept_header[RW]

Public Class Methods

new(application:, header:) click to toggle source
# File lib/drillbit/accept_header.rb, line 8
def initialize(application:, header:)
  self.application       = application
  self.raw_accept_header = header || ''
end

Public Instance Methods

content_type() click to toggle source
# File lib/drillbit/accept_header.rb, line 17
def content_type
  accept_header_data[1]
end
invalid?() click to toggle source
# File lib/drillbit/accept_header.rb, line 25
def invalid?
  accept_header_data.nil?
end
to_s() click to toggle source
# File lib/drillbit/accept_header.rb, line 29
def to_s
  raw_accept_header
end
valid?() click to toggle source
# File lib/drillbit/accept_header.rb, line 21
def valid?
  !invalid?
end
version() click to toggle source
# File lib/drillbit/accept_header.rb, line 13
def version
  accept_header_data[2]
end

Private Instance Methods

accept_header_data() click to toggle source
# File lib/drillbit/accept_header.rb, line 35
def accept_header_data
  raw_accept_header.match(accept_header_format)
end
accept_header_format() click to toggle source

rubocop:disable Metrics/LineLength

# File lib/drillbit/accept_header.rb, line 40
def accept_header_format
  %r{(?:(?<=\A)|(?<=,))application/#{application_vendor}(?:\+(\w+))?(?:;version=(#{version_format}))?(?:(?=\z)|(?=,))}
end
application_vendor() click to toggle source

rubocop:enable Metrics/LineLength

# File lib/drillbit/accept_header.rb, line 45
def application_vendor
  "vnd\\.#{application}"
end
version_format() click to toggle source
# File lib/drillbit/accept_header.rb, line 49
def version_format
  '\\d+(?:\\.\\d+){0,2}(?:beta(?:\\d*))?'
end