lib/accept_headers/language/negotiator.rb in accept_headers-0.0.4 vs lib/accept_headers/language/negotiator.rb in accept_headers-0.0.5
- old
+ new
@@ -4,22 +4,20 @@
module AcceptHeaders
class Language
class Negotiator
include Negotiatable
- LANGUAGE_PATTERN = /^\s*(?<primary_tag>[\w]{1,8}|\*)(?:\s*\-\s*(?<subtag>[\w]{1,8}|\*))?\s*$/
-
private
def parse(original_header)
header = original_header.dup
header.sub!(/\AAccept-Language:\s*/, '')
header.strip!
return [Language.new] if header.empty?
languages = []
header.split(',').each do |entry|
language_arr = entry.split(';', 2)
next if language_arr[0].nil?
- language_range = LANGUAGE_PATTERN.match(language_arr[0])
+ language_range = Language::LANGUAGE_TAG_PATTERN.match(language_arr[0])
next if language_range.nil?
begin
languages << Language.new(
language_range[:primary_tag],
language_range[:subtag],