class Nitlink::ParamExtractor
Constants
- LEADING_OWS
- QUOTED_PAIR
- QUOTED_VALUE
- TRAILING_OWS
Public Instance Methods
extract(rest)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 9 def extract(rest) @rest = rest parameter_strings = Splitter.new(rest).split_on_unquoted(';') raw_params = parameter_strings.map do |parameter_str| strip_ows(parameter_str).split('=', 2) end return format(raw_params) end
Private Instance Methods
format(raw_params)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 21 def format(raw_params) raw_params.map do |raw_param_name, raw_param_value| next if !raw_param_name param_name = rstrip_ows(raw_param_name.downcase) if raw_param_value param_value = lstrip_ows(raw_param_value) param_value = format_quoted_value(param_value) if quoted?(param_value) else param_value = nil end [param_name, param_value] end.compact end
format_quoted_value(quoted_value)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 37 def format_quoted_value(quoted_value) without_quotes = quoted_value.strip[QUOTED_VALUE, 1] without_quotes.gsub(QUOTED_PAIR) { |match| match.chars.to_a.last } end
lstrip_ows(str)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 46 def lstrip_ows(str) str.gsub(LEADING_OWS, '') end
quoted?(param_value)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 42 def quoted?(param_value) param_value =~ QUOTED_VALUE end
rstrip_ows(str)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 50 def rstrip_ows(str) str.gsub(TRAILING_OWS, '') end
strip_ows(str)
click to toggle source
# File lib/nitlink/param_extractor.rb, line 54 def strip_ows(str) rstrip_ows(lstrip_ows str) end