Class: Swaggable::MimeTypesCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/swaggable/mime_types_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeMimeTypesCollection

Returns a new instance of MimeTypesCollection.



13
14
15
# File 'lib/swaggable/mime_types_collection.rb', line 13

def initialize
  @list = []
end

Instance Method Details

#<<(entry) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/swaggable/mime_types_collection.rb', line 17

def << entry
  entry = case entry
          when Symbol, String then MimeTypeDefinition.new entry
          else entry
          end

  if n = list.index(entry)
    list[n] = entry
  else
    list << entry
  end
end

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



46
47
48
# File 'lib/swaggable/mime_types_collection.rb', line 46

def == other
  count == other.count && other.each {|e| include? e }
end

#[](key) ⇒ Object



34
35
36
# File 'lib/swaggable/mime_types_collection.rb', line 34

def [] key
  list.detect {|e| e == key }
end

#each(*args, &block) ⇒ Object



30
31
32
# File 'lib/swaggable/mime_types_collection.rb', line 30

def each *args, &block
  list.each(*args, &block)
end

#hashObject



52
53
54
# File 'lib/swaggable/mime_types_collection.rb', line 52

def hash
  name.hash
end

#inspectObject



38
39
40
# File 'lib/swaggable/mime_types_collection.rb', line 38

def inspect
  "#<Swaggable::MimeTypesCollection: #{list.map(&:name).join(', ')}>"
end

#merge!(other) ⇒ Object



42
43
44
# File 'lib/swaggable/mime_types_collection.rb', line 42

def merge! other
  other.each {|e| self << e }
end