Module: AcceptLanguage

Defined in:
lib/accept_language.rb,
lib/accept_language/parser.rb,
lib/accept_language/intersection.rb

Overview

Tiny library for parsing the Accept-Language header.

Defined Under Namespace

Modules: Parser Classes: Intersection

Class Method Summary collapse

Class Method Details

.intersection(raw_input, *supported_langs, two_letter_truncate: true) ⇒ Object

Examples:

AcceptLanguage.intersection('ja, en-gb;q=0.8, en;q=0.7', :ar, :ja) # => :ja

7
8
9
# File 'lib/accept_language.rb', line 7

def self.intersection(raw_input, *supported_langs, two_letter_truncate: true)
  Intersection.new(raw_input, *supported_langs, two_letter_truncate: two_letter_truncate).call
end

.parse(raw_input, two_letter_truncate: false) ⇒ Object

Examples:

AcceptLanguage.parse('ja, en-gb;q=0.8, en;q=0.7') # => { ja: 1.0, "en-gb": 0.8, en: 0.7 }

13
14
15
# File 'lib/accept_language.rb', line 13

def self.parse(raw_input, two_letter_truncate: false)
  Parser.call(raw_input, two_letter_truncate: two_letter_truncate)
end