Class: AcceptLanguage::Matcher Private
- Inherits:
-
Object
- Object
- AcceptLanguage::Matcher
- Defined in:
- lib/accept_language/matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class is intended for internal use by Parser and should not be instantiated directly.
Matches Accept-Language header values against application-supported languages to determine the optimal language choice. Handles quality values, wildcards, and language tag matching according to RFC 2616 specifications.
Constant Summary collapse
- WILDCARD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"*"
Instance Attribute Summary collapse
- #excluded_langtags ⇒ Object readonly private
- #preferred_langtags ⇒ Object readonly private
Instance Method Summary collapse
- #call(*available_langtags) ⇒ Object private
-
#initialize(**languages_range) ⇒ Matcher
constructor
private
A new instance of Matcher.
Constructor Details
#initialize(**languages_range) ⇒ Matcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Matcher.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/accept_language/matcher.rb', line 18 def initialize(**languages_range) = ::Set[] = [] languages_range.select do |langtag, quality| if quality.zero? << langtag unless wildcard?(langtag) else level = (quality * 1_000).to_i [level] = langtag end end = .compact.reverse end |
Instance Attribute Details
#excluded_langtags ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/accept_language/matcher.rb', line 15 def end |
#preferred_langtags ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/accept_language/matcher.rb', line 15 def end |
Instance Method Details
#call(*available_langtags) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 |
# File 'lib/accept_language/matcher.rb', line 35 def call(*) raise ::ArgumentError, "Language tags cannot be nil" if .any?(&:nil?) = drop_unacceptable(*) return nil if .empty? find_best_match() end |