diff options
author | Arnaud Meuret <arnaud@meuret.net> | 2013-04-12 15:59:02 +0200 |
---|---|---|
committer | Arnaud Meuret <arnaud@meuret.net> | 2013-04-12 15:59:02 +0200 |
commit | fd53425e33046932cebcf0d3d8f92c3e35cd4472 (patch) | |
tree | d3fc04403170b0b78c580b742fb6fd1810d6e460 | |
parent | 19c58e2b6d0352f399bf7e8ed47a27a58725504c (diff) | |
download | git-fd53425e33046932cebcf0d3d8f92c3e35cd4472.tar.gz |
Make the collection Enumerable
-rw-r--r-- | lib/mime/types.rb | 18 | ||||
-rw-r--r-- | test/test_mime_types.rb | 8 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/mime/types.rb b/lib/mime/types.rb index c5d637750b..f1caf3c883 100644 --- a/lib/mime/types.rb +++ b/lib/mime/types.rb @@ -596,6 +596,14 @@ module MIME def defined_types #:nodoc: @type_variants.values.flatten end + + def count + @type_variants.size + end + + def each + @type_variants.each { |t| yield t } + end @__types__ = self.new(VERSION) @@ -820,6 +828,16 @@ module MIME @__types__[type_id, flags] end + include Enumerable + + def count + @__types__.count + end + + def each + @__types__.each {|t| yield t } + end + # Return the list of MIME::Types which belongs to the file based on # its filename extension. If +platform+ is +true+, then only file # types that are specific to the current platform will be returned. diff --git a/test/test_mime_types.rb b/test/test_mime_types.rb index 77add31af6..0e476382c8 100644 --- a/test/test_mime_types.rb +++ b/test/test_mime_types.rb @@ -70,6 +70,14 @@ class TestMIME_Types < MiniTest::Unit::TestCase #:nodoc: assert_equal(MIME::Types.of('gif', true), MIME::Types['image/gif']) assert(MIME::Types.of('zzz').empty?) end + + def test_class_enumerable + assert( MIME::Types.any? {|types| types[0] == 'text/plain'} ) + end + + def test_class_count + assert(MIME::Types.count > 42, "A lot of types are expected to be known.") + end def test_ebook_formats assert_equal( MIME::Types['application/x-mobipocket-ebook'], MIME::Types.type_for("book.mobi")) |