class ShafClient::ContentTypeMap

Attributes

map[R]

Public Class Methods

new() click to toggle source
# File lib/shaf_client/content_type_map.rb, line 9
def initialize
  @map = {}
end

Public Instance Methods

[](content_type, profile = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

strip_parameters(content_type) click to toggle source
# File lib/shaf_client/content_type_map.rb, line 49
def strip_parameters(content_type)
  content_type&.sub(/;.*/, '')
end