Sha256: 34bef2e1b031fa9404d7947987e0aec37a0e40f0cc966df8e87a53266c5d4148

Contents?: true

Size: 587 Bytes

Versions: 2

Compression:

Stored size: 587 Bytes

Contents

module LocaleSetter
  module HTTP
    def self.for(accept_language)
      LocaleSetter::Matcher.match(AcceptLanguageParser.parse(accept_language))
    end

    module AcceptLanguageParser
      LOCALE_SEPARATOR = ','
      WEIGHT_SEPARATOR = ';'

      def self.parse(accept_language)
        locale_fragments = accept_language.split(LOCALE_SEPARATOR)
        weighted_fragments = locale_fragments.map{|f| f.split(WEIGHT_SEPARATOR)}
        sorted_fragments = weighted_fragments.sort_by{|f| -f.last.to_f }
        sorted_fragments.map{|locale, weight| locale}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
locale_setter-0.1.1 lib/locale_setter/http.rb
locale_setter-0.1.0 lib/locale_setter/http.rb