Class: HTTP::Accept::Languages::Locales
- Inherits:
-
Array
- Object
- Array
- HTTP::Accept::Languages::Locales
- Defined in:
- lib/http/accept/languages.rb
Overview
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
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Class Method Summary collapse
Instance Method Summary collapse
-
#&(languages) ⇒ Object
Returns the intersection of others retaining order.
- #freeze ⇒ Object
- #include?(locale_name) ⇒ Boolean
-
#initialize(names) ⇒ Locales
constructor
A new instance of Locales.
Constructor Details
#initialize(names) ⇒ Locales
Returns a new instance of Locales.
51 52 53 54 55 56 57 58 59 |
# File 'lib/http/accept/languages.rb', line 51 def initialize(names) super(names) @patterns = {} self.each{|name| self.class.(name, @patterns)} self.freeze end |
Instance Attribute Details
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
67 68 69 |
# File 'lib/http/accept/languages.rb', line 67 def patterns @patterns end |
Class Method Details
.expand(locale, into) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/http/accept/languages.rb', line 39 def self.(locale, into) parts = locale.split('-') while parts.size > 0 key = parts.join('-') into[key] ||= locale parts.pop end end |
Instance Method Details
#&(languages) ⇒ Object
Returns the intersection of others retaining order.
70 71 72 |
# File 'lib/http/accept/languages.rb', line 70 def & languages languages.collect{|language_range| @patterns[language_range.locale]}.compact end |
#freeze ⇒ Object
61 62 63 64 65 |
# File 'lib/http/accept/languages.rb', line 61 def freeze @patterns.freeze super end |
#include?(locale_name) ⇒ Boolean
74 75 76 |
# File 'lib/http/accept/languages.rb', line 74 def include? locale_name @patterns.include? locale_name end |