Class: HttpHeaders::AcceptLanguage::Entry
- Inherits:
-
Object
- Object
- HttpHeaders::AcceptLanguage::Entry
- Defined in:
- lib/http_headers/accept_language.rb
Constant Summary collapse
- DELIMITER =
'-'
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](parameter) ⇒ Object
-
#initialize(locale, index:, parameters:) ⇒ Entry
constructor
A new instance of Entry.
-
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention.
- #to_header ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(locale, index:, parameters:) ⇒ Entry
Returns a new instance of Entry.
16 17 18 19 20 21 22 23 24 |
# File 'lib/http_headers/accept_language.rb', line 16 def initialize(locale, index:, parameters:) self.locale = locale # TODO: support extlang correctly, maybe we don't even need this self.language, self.region = locale.split(DELIMITER) self.parameters = parameters self.index = index freeze end |
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
14 15 16 |
# File 'lib/http_headers/accept_language.rb', line 14 def language @language end |
#locale ⇒ Object
Returns the value of attribute locale.
14 15 16 |
# File 'lib/http_headers/accept_language.rb', line 14 def locale @locale end |
#region ⇒ Object
Returns the value of attribute region.
14 15 16 |
# File 'lib/http_headers/accept_language.rb', line 14 def region @region end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 34 35 |
# File 'lib/http_headers/accept_language.rb', line 31 def <=>(other) quality = other.q <=> q return quality unless quality.zero? index <=> other.send(:index) end |
#[](parameter) ⇒ Object
37 38 39 |
# File 'lib/http_headers/accept_language.rb', line 37 def [](parameter) parameters.fetch(String(parameter).to_sym) end |
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention
27 28 29 |
# File 'lib/http_headers/accept_language.rb', line 27 def q parameters.fetch(:q) { 1.0 }.to_f end |
#to_header ⇒ Object
41 42 43 |
# File 'lib/http_headers/accept_language.rb', line 41 def to_header to_s end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/http_headers/accept_language.rb', line 45 def to_s [locale].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ') end |