Sha256: 6ac259e3fb81cb5605760fcc279fe10db5a573fac4c89b0158491edf395c9b60

Contents?: true

Size: 609 Bytes

Versions: 2

Compression:

Stored size: 609 Bytes

Contents

module LocaleSetter
  module HTTP
    def self.for(accept_language, available)
      LocaleSetter::Matcher.match(AcceptLanguageParser.parse(accept_language), available)
    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.4.0 lib/locale_setter/http.rb
locale_setter-0.3.0 lib/locale_setter/http.rb