Class: Protocol::Media::Type

Inherits:
Range
  • Object
show all
Defined in:
lib/protocol/media/type.rb

Overview

A concrete media type and its parameters.

Constant Summary

Constants inherited from Range

Range::MEDIA_TYPE, Range::PARAMETER, Range::QUOTED_STRING, Range::TOKEN

Instance Attribute Summary

Attributes inherited from Range

#The subtype, e.g. `plain` or `*`., #The top-level type, e.g. `text` or `*`., #parameters, #subtype, #type

Class Method Summary collapse

Methods inherited from Range

#The media range parameters.=, #eql?, #freeze, #hash, #initialize, #match?, #name, parse, parse_parameters, #to_s, unquote

Constructor Details

This class inherits a constructor from Protocol::Media::Range

Class Method Details

.build(type, subtype, parameters = {}) ⇒ Object

Build a normalized concrete media type.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/protocol/media/type.rb', line 30

def self.build(type, subtype, parameters = {})
	# Concrete media types cannot use a wildcard type:
	if type == "*"
		raise ArgumentError, "Media types cannot contain wildcards: #{type}/#{subtype}"
	end
	
	# Concrete media types cannot use a wildcard subtype:
	if subtype == "*"
		raise ArgumentError, "Media types cannot contain wildcards: #{type}/#{subtype}"
	end
	
	return super
end

.for(value) ⇒ Object

Parse strings and normalize compatible media type objects.



16
17
18
19
20
21
22
# File 'lib/protocol/media/type.rb', line 16

def self.for(value)
	if value.is_a?(String)
		return parse(value)
	end
	
	return build(value.type, value.subtype, value.parameters)
end