Class: MediaTypes::Serialization::Utils::AcceptLanguageHeader::Entry
- Inherits:
-
Object
- Object
- MediaTypes::Serialization::Utils::AcceptLanguageHeader::Entry
- Defined in:
- lib/media_types/serialization/utils/accept_language_header.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.
41 42 43 44 45 46 47 48 49 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 41 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.
39 40 41 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 39 def language @language end |
#locale ⇒ Object
Returns the value of attribute locale.
39 40 41 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 39 def locale @locale end |
#region ⇒ Object
Returns the value of attribute region.
39 40 41 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 39 def region @region end |
Instance Method Details
#<=>(other) ⇒ Object
56 57 58 59 60 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 56 def <=>(other) quality = other.q <=> q return quality unless quality.zero? index <=> other.send(:index) end |
#[](parameter) ⇒ Object
62 63 64 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 62 def [](parameter) parameters.fetch(String(parameter).to_sym) end |
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention
52 53 54 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 52 def q parameters.fetch(:q) { 1.0 }.to_f end |
#to_header ⇒ Object
66 67 68 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 66 def to_header to_s end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/media_types/serialization/utils/accept_language_header.rb', line 70 def to_s [locale].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ') end |