Class: HttpHeaders::Accept::Entry
- Inherits:
-
Object
- Object
- HttpHeaders::Accept::Entry
- Defined in:
- lib/http_headers/accept.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.
11 12 13 14 15 16 17 |
# File 'lib/http_headers/accept.rb', line 11 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.
19 20 21 |
# File 'lib/http_headers/accept.rb', line 19 def media_type @media_type end |
Instance Method Details
#<=>(other) ⇒ Object
26 27 28 29 30 |
# File 'lib/http_headers/accept.rb', line 26 def <=>(other) quality = other.q <=> q return quality unless quality.zero? index <=> other.send(:index) end |
#[](parameter) ⇒ Object
32 33 34 |
# File 'lib/http_headers/accept.rb', line 32 def [](parameter) parameters.fetch(String(parameter).to_sym) end |
#q ⇒ Object
noinspection RubyInstanceMethodNamingConvention
22 23 24 |
# File 'lib/http_headers/accept.rb', line 22 def q parameters.fetch(:q) { 1.0 }.to_f end |
#to_header ⇒ Object
36 37 38 |
# File 'lib/http_headers/accept.rb', line 36 def to_header to_s end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/http_headers/accept.rb', line 40 def to_s [media_type].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ') end |