Class: ShafClient::ContentTypeMap

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shaf_client/content_type_map.rb

Instance Method Summary collapse

Constructor Details

#initializeContentTypeMap

Returns a new instance of ContentTypeMap.



9
10
11
# File 'lib/shaf_client/content_type_map.rb', line 9

def initialize
  @map = {}
end

Instance Method Details

#[](content_type, profile = nil) ⇒ Object



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

def [](content_type, profile = nil)
  key = key_for(content_type, profile)
  map.fetch(key) do
    key = key_for(content_type, nil)
    map[key]
  end
end

#[]=(content_type, profile = nil, value) ⇒ Object



21
22
23
24
# File 'lib/shaf_client/content_type_map.rb', line 21

def []=(content_type, profile = nil, value)
  key = key_for(content_type, profile)
  map[key] = value
end

#delete(content_type, profile = nil) ⇒ Object



31
32
33
34
# File 'lib/shaf_client/content_type_map.rb', line 31

def delete(content_type, profile = nil)
  key = key_for(content_type, profile)
  map.delete(key)
end

#key?(content_type, profile = nil) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/shaf_client/content_type_map.rb', line 26

def key?(content_type, profile = nil)
  key = key_for(content_type, profile)
  map.key? key
end

#key_for(content_type, profile) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/shaf_client/content_type_map.rb', line 36

def key_for(content_type, profile)
  return unless content_type

  key = content_type.to_s.downcase
  key = strip_parameters(key)
  key << "_#{profile.to_s.downcase}" if profile
  key
end