Class: Swaggable::MimeTypeDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggable/mime_type_definition.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ MimeTypeDefinition

Returns a new instance of MimeTypeDefinition.



3
4
5
6
7
8
9
# File 'lib/swaggable/mime_type_definition.rb', line 3

def initialize id
  @type, @subtype, @options = case id
                              when String then parse_string id
                              when Symbol then parse_symbol id
                              else raise "#{id.inspect} not valid"
                              end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



37
38
39
40
41
42
43
# File 'lib/swaggable/mime_type_definition.rb', line 37

def == other
  case other
  when self.class then name == other.name
  when String, Symbol then name == self.class.new(other).name
  else false
  end
end

#hashObject



47
48
49
# File 'lib/swaggable/mime_type_definition.rb', line 47

def hash
  name.hash
end

#http_stringObject



17
18
19
20
21
# File 'lib/swaggable/mime_type_definition.rb', line 17

def http_string
  http = name
  http += options if options
  http
end

#inspectObject



33
34
35
# File 'lib/swaggable/mime_type_definition.rb', line 33

def inspect
  "#<Swaggable::ContentTypeDefinition: #{type}/#{subtype}>"
end

#nameObject Also known as: to_s



11
12
13
# File 'lib/swaggable/mime_type_definition.rb', line 11

def name
  "#{type}/#{subtype}"
end

#to_symObject



23
24
25
26
27
28
29
30
31
# File 'lib/swaggable/mime_type_definition.rb', line 23

def to_sym
  string = if type == 'application'
             subtype
           else
             name
           end

  string.gsub(/[-\.\/]+/,'_').to_sym
end