<commit_before>require 'strscan'


module AuthorizationHeaderParser
  VERSION = '1.0.0'
  InvalidHeader = Class.new(StandardError)
  
  # Parse a custom scheme + params Authorization header.
  #
  #   parse('absurd-auth token="<PASSWORD>"') #=> ['absurd-auth', {'token' => '<PASSWORD>}]
  def parse(value)
    scanner = StringScanner.new(value)
    scheme = scanner.scan(NON_WHITESPACE)
    raise InvalidHeader.new("Scheme not provided") unless scheme
    scanner.skip(WHITESPACE)
    
    [scheme.strip, extract_params_from_scanner(scanner)]
  end
  
  # Parse Authorization params. Most useful in combination with Rack::Auth::AbstractRequest
  #
  # For instance, with 'Authorization: absurd-auth token="<PASSWORD>"':
  #
  #   auth = Rack::Auth::AbstractRequest.new(env)
  #   params = parse(auth.params) #=> {'token' => '<PASSWORD>}
  def parse_params(string)
    extract_params_from_scanner(StringScanner.new(string))<commit_msg>Update the documentation block<commit_after>require 'strscan'


module AuthorizationHeaderParser
  VERSION = '1.0.0'
  InvalidHeader = Class.new(StandardError)
  
  # Parse a custom scheme + params Authorization header.
  #
  #   parse('absurd-auth token="<PASSWORD>"') #=> ['absurd-auth', {'token' => '<PASSWORD>'}]
  def parse(value)
    scanner = StringScanner.new(value)
    scheme = scanner.scan(NON_WHITESPACE)
    raise InvalidHeader.new("Scheme not provided") unless scheme
    scanner.skip(WHITESPACE)
    
    [scheme.strip, extract_params_from_scanner(scanner)]
  end
  
  # Parse Authorization params. Most useful in combination with Rack::Auth::AbstractRequest
  #
  # For instance, with 'Authorization: absurd-auth token="<PASSWORD>"':
  #
  #   auth = Rack::Auth::AbstractRequest.new(env)
  #   params = parse(auth.params) #=> {'token' => '<PASSWORD>}
  def parse_params(string)
    extract_params_from_scanner(StringScanner.new(string))
{'fraction_non_alphanumeric': 0.1320254506892895, 'fraction_numerical': 0.003181336161187699, 'mean_word_length': 4.616071428571429, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4132471', 'n_tokens_mistral': 608, 'n_tokens_neox': 599, 'n_words': 122}