Class: HTTP::MimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/http/mime_type.rb

Overview

Yes, HTTP bundles its own MIME type library. Maybe it should be spun off as a separate gem or something.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, shortcut = nil) ⇒ MimeType

Returns a new instance of MimeType.



24
25
26
27
28
29
# File 'lib/http/mime_type.rb', line 24

def initialize(type, shortcut = nil)
  @type, @shortcut = type, shortcut
  @parse_with = @emit_with = nil

  self.class.register self
end

Instance Attribute Details

#shortcutObject (readonly)

Returns the value of attribute shortcut.



22
23
24
# File 'lib/http/mime_type.rb', line 22

def shortcut
  @shortcut
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/http/mime_type.rb', line 22

def type
  @type
end

Class Method Details

.[](type) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/http/mime_type.rb', line 13

def [](type)
  if type.is_a? Symbol
    @shortcuts[type]
  else
    @mime_types[type]
  end
end

.register(obj) ⇒ Object



8
9
10
11
# File 'lib/http/mime_type.rb', line 8

def register(obj)
  @mime_types[obj.type] = obj
  @shortcuts[obj.shortcut] = obj if obj.shortcut
end

Instance Method Details

#emit(obj) ⇒ Object



44
45
46
# File 'lib/http/mime_type.rb', line 44

def emit(obj)
  @emit_with  ? @emit_with[obj]  : obj
end

#emit_with(&block) ⇒ Object



36
37
38
# File 'lib/http/mime_type.rb', line 36

def emit_with(&block)
  @emit_with = block
end

#parse(obj) ⇒ Object



40
41
42
# File 'lib/http/mime_type.rb', line 40

def parse(obj)
  @parse_with ? @parse_with[obj] : obj
end

#parse_with(&block) ⇒ Object

Define



32
33
34
# File 'lib/http/mime_type.rb', line 32

def parse_with(&block)
  @parse_with = block
end