class HTTP::Accept::Languages::Locales
Provides an efficient data-structure for matching the Accept-Languages header to set of available locales according to tools.ietf.org/html/rfc7231#section-5.3.5 and tools.ietf.org/html/rfc4647#section-2.3
Attributes
names[R]
patterns[R]
Public Class Methods
expand(locale, into)
click to toggle source
# File lib/http/accept/languages.rb, line 42 def self.expand(locale, into) parts = locale.split('-') while parts.size > 0 key = parts.join('-') into[key] ||= locale parts.pop end end
new(names)
click to toggle source
# File lib/http/accept/languages.rb, line 54 def initialize(names) @names = names @patterns = {} @names.each{|name| self.class.expand(name, @patterns)} self.freeze end
Public Instance Methods
&(languages)
click to toggle source
Returns the intersection of others retaining order.
# File lib/http/accept/languages.rb, line 80 def & languages languages.collect{|language_range| @patterns[language_range.locale]}.compact end
+(others)
click to toggle source
# File lib/http/accept/languages.rb, line 92 def + others self.class.new(@names + others.to_a) end
each(&block)
click to toggle source
# File lib/http/accept/languages.rb, line 70 def each(&block) return to_enum unless block_given? @names.each(&block) end
freeze()
click to toggle source
Calls superclass method
# File lib/http/accept/languages.rb, line 63 def freeze @names.freeze @patterns.freeze super end
include?(locale_name)
click to toggle source
# File lib/http/accept/languages.rb, line 84 def include? locale_name @patterns.include? locale_name end
join(*args)
click to toggle source
# File lib/http/accept/languages.rb, line 88 def join(*args) @names.join(*args) end
to_a()
click to toggle source
# File lib/http/accept/languages.rb, line 96 def to_a @names end