class ContentType

ContentType structure

Constants

VERSION

Attributes

parameters[R]
subtype[R]
type[R]

Public Class Methods

new(parsed) click to toggle source
# File lib/content_type.rb, line 12
def initialize(parsed)
  parsed = [parsed] unless parsed.is_a? Array

  @type       = parsed.first[:type].to_s.downcase
  @subtype    = parsed.first[:subtype].to_s.downcase
  @parameters = Hash[parse_parameters parsed[1..-1]]
end
parse(str) click to toggle source
# File lib/content_type.rb, line 38
def self.parse(str)
  new Parser.new.parse str
end

Public Instance Methods

charset() click to toggle source
# File lib/content_type.rb, line 24
def charset
  parameters["charset"]
end
inspect() click to toggle source
# File lib/content_type.rb, line 28
def inspect
  "#<ContentType #{mime_type} #{parameters.inspect}>"
end
mime_type() click to toggle source
# File lib/content_type.rb, line 20
def mime_type
  "#{type}/#{subtype}"
end
to_s() click to toggle source
# File lib/content_type.rb, line 32
def to_s
  (["#{mime_type}"] + parameters.map { |k, v| "#{k}=#{v.to_s.inspect}" })
    .compact.join("; ")
end
Also aliased as: to_str
to_str()
Alias for: to_s

Protected Instance Methods

parse_parameters(list) click to toggle source
# File lib/content_type.rb, line 44
def parse_parameters(list)
  Array(list).map do |hash|
    [
      hash[:parameter][:attribute].to_s.downcase,
      hash[:parameter][:value].to_s
    ]
  end
end