Class: HttpHeaders::ContentType::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/http_headers/content_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_type, parameters:, **_opts) ⇒ Entry

swallow index:



13
14
15
16
17
18
# File 'lib/http_headers/content_type.rb', line 13

def initialize(content_type, parameters:, **_opts) # swallow index:
  self.content_type = content_type
  self.parameters = parameters

  freeze
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



20
21
22
# File 'lib/http_headers/content_type.rb', line 20

def content_type
  @content_type
end

Instance Method Details

#[](parameter) ⇒ Object



27
28
29
# File 'lib/http_headers/content_type.rb', line 27

def [](parameter)
  parameters.fetch(String(parameter).to_sym)
end

#charsetObject

noinspection RubyInstanceMethodNamingConvention



23
24
25
# File 'lib/http_headers/content_type.rb', line 23

def charset
  parameters.fetch(:charset) { nil }
end

#to_headerObject



31
32
33
# File 'lib/http_headers/content_type.rb', line 31

def to_header
  to_s
end

#to_sObject



35
36
37
# File 'lib/http_headers/content_type.rb', line 35

def to_s
  [content_type].concat(parameters.map { |k, v| "#{k}=#{v}" }).compact.reject(&:empty?).join('; ')
end