Class: MediaTypes::Serialization::Utils::AcceptHeader::Entry
- Inherits:
-
Object
- Object
- MediaTypes::Serialization::Utils::AcceptHeader::Entry
- Defined in:
- lib/media_types/serialization/utils/accept_header.rb
Instance Attribute Summary collapse
-
#media_type ⇒ Object
readonly
Returns the value of attribute media_type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](parameter) ⇒ Object
-
#initialize(media_type, index:, parameters:) ⇒ Entry
constructor
A new instance of Entry.
-
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention.
- #to_header ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(media_type, index:, parameters:) ⇒ Entry
Returns a new instance of Entry.
36 37 38 39 40 41 42 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 36 def initialize(media_type, index:, parameters:) self.media_type = media_type self.parameters = parameters self.index = index freeze end |
Instance Attribute Details
#media_type ⇒ Object
Returns the value of attribute media_type.
44 45 46 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 44 def media_type @media_type end |
Instance Method Details
#<=>(other) ⇒ Object
51 52 53 54 55 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 51 def <=>(other) quality = other.q <=> q return quality unless quality.zero? index <=> other.send(:index) end |
#[](parameter) ⇒ Object
57 58 59 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 57 def [](parameter) parameters.fetch(String(parameter).to_sym) end |
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention
47 48 49 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 47 def q parameters.fetch(:q) { 1.0 }.to_f end |
#to_header ⇒ Object
61 62 63 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 61 def to_header to_s end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/media_types/serialization/utils/accept_header.rb', line 65 def to_s [media_type].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ') end |